<!Doctype html>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
	<meta name="viewport" content="width=device-width, initial-scale=1.0" />
	<title>PHP 运算符 | 菜鸟教程</title>

  <meta name='robots' content='max-image-preview:large' />
<link rel='stylesheet' id='classic-theme-styles-css' href='../0/classic-themes.min.css?ver=6.2' type='text/css' media='all' />
<link rel="canonical" href="../php/php-operators.html" />
<meta name="keywords" content="PHP 运算符">
<meta name="description" content="PHP 运算符   本章节我们将讨论 PHP 中不同运算符的应用。 在 PHP 中，赋值运算符 = 用于给变量赋值。 在 PHP 中，算术运算符 + 用于把值加在一起。   PHP 算术运算符   运算符 名称 描述 实例 结果   x + y 加 x 和 y 的和 2 + 2 4   x - y 减 x 和 y 的差 5 - 2 3   x * y 乘 x 和 y 的积 5 * 2 10   x / y 除 x 和 y 的商 15 /..">
		
	<link rel="shortcut icon" href="https://static.runoob.com/images/favicon.ico">
	<link rel="stylesheet" href="../0/style.css?v=1.170" type="text/css" media="all" />	
	<link rel="stylesheet" href="../0/font-awesome.min.css" media="all" />	
  <!--[if gte IE 9]><!-->
  <script src=""></script>
  <!--<![endif]-->
  <!--[if lt IE 9]>
     <script src=""></script>
     <script src=""></script>
  <![endif]-->
  <link rel="apple-touch-icon" href="https://static.runoob.com/images/icon/mobile-icon.png"/>
  <meta name="apple-mobile-web-app-title" content="菜鸟教程">
</head>
<body>

<!--  头部 -->
<div class="container logo-search">

  <div class="col search row-search-mobile">
    <form action="index.php">
      <input class="placeholder" placeholder="搜索……" name="s" autocomplete="off">
      
    </form>
  </div>

  <div class="row">
    <div class="col logo">
      <h1><a href="../">菜鸟教程 -- 学的不仅是技术，更是梦想！</a></h1>
    </div>
        <div class="col right-list"> 
    <button class="btn btn-responsive-nav btn-inverse" data-toggle="collapse" data-target=".nav-main-collapse" id="pull" style=""> <i class="fa fa-navicon"></i> </button>
    </div>
        
    <div class="col search search-desktop last">
      <div class="search-input" >
      <form action="//www.runoob.com/" target="_blank">
        <input class="placeholder" id="s" name="s" placeholder="搜索……"  autocomplete="off" style="height: 44px;">
      </form>
      
      </div>
    </div>
  </div>
</div>



<!-- 导航栏 -->
<!-- 导航栏 -->
<div class="container navigation">
	<div class="row">
		<div class="col nav">
			<ul class="pc-nav" id="runoob-detail-nav">
				<li><a href="../">首页</a></li>
				<li><a href="../html/html-tutorial.html">HTML</a></li>
				<li><a href="../css/css-tutorial.html">CSS</a></li>
				<li><a href="../js/js-tutorial.html">JavaScript</a></li>
				<li><a href="javascript:void(0);" data-id="vue">Vue</a></li>
				<li><a href="javascript:void(0);" data-id="bootstrap">Bootstrap</a></li>
				<li><a href="../nodejs/nodejs-tutorial.html">NodeJS</a></li>
				<li><a href="../python3/python3-tutorial.html">Python3</a></li>
				<li><a href="../python/python-tutorial.html">Python2</a></li>
				<li><a href="../java/java-tutorial.html">Java</a></li>
				<li><a href="../cprogramming/c-tutorial.html">C</a></li>
				<li><a href="../cplusplus/cpp-tutorial.html">C++</a></li>
				<li><a href="../csharp/csharp-tutorial.html">C#</a></li>
				<li><a href="../go/go-tutorial.html">Go</a></li>
				<li><a href="../sql/sql-tutorial.html">SQL</a></li>
				<li><a href="../linux/linux-tutorial.html">Linux</a></li>
				<li><a href="../jquery/jquery-tutorial.html">jQuery</a></li>
				<li><a href="../browser-history">本地书签</a></li>
				<!--
			
				<li><a href="../w3cnote/knowledge-start.html" style="font-weight: bold;" onclick="_hmt.push(['_trackEvent', '星球', 'click', 'start'])" title="我的圈子">我的圈子</a></li>				
				<li><a href="javascript:;" class="runoob-pop">登录</a></li>
				-->
      		</ul>
			<ul class="mobile-nav">
				<li><a href="../">首页</a></li>
				<li><a href="../html/html-tutorial.html">HTML</a></li>
				<li><a href="../css/css-tutorial.html">CSS</a></li>
				<li><a href="../js/js-tutorial.html">JS</a></li>
				<li><a href="../browser-history">本地书签</a></li>
				<li><a href="javascript:void(0)" class="search-reveal">Search</a> </li>
			</ul>
			
		</div>
	</div>
</div>

<div class="container sub-navigation sub-navigation-articles" style="display:none">
	<div class="row">
		<div class="col nav-sub">
		<ul id="python">
			<li class="cat-item"><a href="../python3/python3-tutorial.html">Python3 教程 <i class="fa fa-external-link" aria-hidden="true"></i></a></li>
			<li class="cat-item"><a href="../python/python-tutorial.html">Python2 教程 <i class="fa fa-external-link" aria-hidden="true"></i></a></li>
		</ul>
		<ul id="vue">
			<li class="cat-item"><a href="../vue3/vue3-tutorial.html">Vue3 教程 <i class="fa fa-external-link" aria-hidden="true"></i></a></li>
			<li class="cat-item"><a href="../vue/vue-tutorial.html">vue2 教程 <i class="fa fa-external-link" aria-hidden="true"></i></a></li>
		</ul>

		<ul id="bootstrap">
			<li class="cat-item"><a href="../bootstrap/bootstrap-tutorial.html">Bootstrap3 教程 <i class="fa fa-external-link" aria-hidden="true"></i></a></li>
			<li class="cat-item"><a href="../bootstrap4/bootstrap4-tutorial.html">Bootstrap4 教程 <i class="fa fa-external-link" aria-hidden="true"></i></a></li>
			<li class="cat-item"><a href="../bootstrap5/bootstrap5-tutorial.html">Bootstrap5 教程 <i class="fa fa-external-link" aria-hidden="true"></i></a></li>
			<li class="cat-item"><a href="../bootstrap/bootstrap-v2-tutorial.html">Bootstrap2 教程 <i class="fa fa-external-link" aria-hidden="true"></i></a></li>
		</ul>
		</div>
	</div>
</div><!--  内容  -->
<div class="container main">
	<!-- 中间 -->
	<div class="row">
	
<div class="runoob-col-md2">
<div class="left-column">
	<div class="tab" style="overflow: hidden;text-overflow: ellipsis;white-space: nowrap;">
	<i class="fa fa-list" aria-hidden="true"></i> 
	<span>PHP 教程</span>
	<a data-cate="13" href="javascript:void(0);" title="夜间模式"  id="moon"><i class="fa fa-moon-o" aria-hidden="true" style="line-height: 28px;font-size: 1.2em;margin: 2px 4px 0;"></i></a>
	<a data-cate="13" style="display:none;" href="javascript:void(0);" title="日间模式"  id="sun" ><i class="fa fa-sun-o" aria-hidden="true" style="line-height: 28px;font-size: 1.2em;margin: 2px 4px 0;line-height: 28px;
}"></i></a>

	</div>
	<div class="sidebar-box gallery-list">
		<div class="design" id="leftcolumn">
						<a target="_top" title="PHP 教程"  href="../php/php-tutorial.html" >
			PHP 教程			</a>
						<a target="_top" title="PHP 简介"  href="../php/php-intro.html" >
			PHP 简介			</a>
						<a target="_top" title="PHP 安装"  href="../php/php-install.html" >
			PHP 安装			</a>
						<a target="_top" title="PHP 语法"  href="../php/php-syntax.html" >
			PHP 语法			</a>
						<a target="_top" title="PHP 变量"  href="../php/php-variables.html" >
			PHP 变量			</a>
			<a target="_top" title="PHP  echo/print 语句" href="../php/php-echo-print.html"> PHP  echo/print </a>
<a target="_top" title="PHP EOF(heredoc) 使用说明" href="../php/php-eof-heredoc.html"> PHP EOF(heredoc) </a>
<a target="_top" title="PHP  数据类型" href="../php/php-datatypes.html"> PHP  数据类型 </a>
<a target="_top" title="PHP 类型比较" href="../php/php-types-comparisons.html"> PHP 类型比较 </a>
<a target="_top" title="PHP  常量" href="../php/php-constants.html"> PHP  常量 </a>			<a target="_top" title="PHP 字符串变量"  href="../php/php-string.html" >
			PHP 字符串			</a>
						<a target="_top" title="PHP 运算符"  href="../php/php-operators.html" >
			PHP 运算符			</a>
						<a target="_top" title="PHP If&#8230;Else 语句"  href="../php/php-if-else.html" >
			PHP If...Else			</a>
						<a target="_top" title="PHP Switch 语句"  href="../php/php-switch.html" >
			PHP Switch			</a>
						<a target="_top" title="PHP 数组"  href="../php/php-arrays.html" >
			PHP 数组			</a>
						<a target="_top" title="PHP 数组排序"  href="../php/php-arrays-sort.html" >
			PHP 数组排序			</a>
			<a target="_top" href="../php/php-superglobals.html">
	PHP 超级全局变量	</a>			<a target="_top" title="PHP While 循环"  href="../php/php-looping.html" >
			PHP While 循环			</a>
						<a target="_top" title="PHP For 循环"  href="../php/php-looping-for.html" >
			PHP For 循环			</a>
						<a target="_top" title="PHP 函数"  href="../php/php-functions.html" >
			PHP 函数			</a>
			<a target="_top" href="../php/php-magic-constant.html">PHP 魔术常量	</a>
<a target="_top" href="php-namespace.html">PHP 命名空间</a>
<a target="_top" href="php-oop.html">PHP 面向对象</a>
<a href="../quiz/php-quiz.html" target="_blank">PHP 测验</a>
<br><h2 class="left"><span class="left_h2">PHP</span> 表单</h2>			<a target="_top" title="PHP 表单"  href="../php/php-forms.html" >
			PHP 表单			</a>
			<a target="_top" href="../php/php-form-validation.html">PHP 表单验证</a>
<a target="_top" href="../php/php-form-required.html">PHP 表单 - 必需字段</a>
<a target="_top" href="../php/php-form-url-email.html">PHP 表单 - 验证邮件和URL</a>
<a target="_top" href="../php/php-form-complete.html">PHP 完整表单实例</a>			<a target="_top" title="PHP $_GET 变量"  href="../php/php-get.html" >
			PHP $_GET 变量			</a>
						<a target="_top" title="PHP $_POST 变量"  href="../php/php-post.html" >
			PHP $_POST 变量			</a>
			<br><h2 class="left"><span class="left_h2">PHP</span> 高级教程</h2>			<a target="_top" title="PHP 多维数组"  href="../php/php-arrays-multi.html" >
			PHP 多维数组			</a>
						<a target="_top" title="PHP date() 函数"  href="../php/php-date.html" >
			PHP 日期			</a>
						<a target="_top" title="PHP include 和 require"  href="../php/php-includes.html" >
			PHP 包含			</a>
						<a target="_top" title="PHP 文件"  href="../php/php-file.html" >
			PHP 文件			</a>
						<a target="_top" title="PHP 文件上传"  href="../php/php-file-upload.html" >
			PHP 文件上传			</a>
						<a target="_top" title="PHP Cookie"  href="../php/php-cookies.html" >
			PHP Cookie			</a>
						<a target="_top" title="PHP Session"  href="../php/php-sessions.html" >
			PHP Session			</a>
						<a target="_top" title="PHP 邮件"  href="../php/php-mail.html" >
			PHP E-mail			</a>
						<a target="_top" title="PHP 安全 E-mail"  href="../php/php-secure-mail.html" >
			PHP 安全 E-mail			</a>
						<a target="_top" title="PHP 错误处理"  href="../php/php-error.html" >
			PHP Error			</a>
						<a target="_top" title="PHP 异常处理"  href="../php/php-exception.html" >
			PHP Exception			</a>
						<a target="_top" title="PHP 过滤器"  href="../php/php-filter.html" >
			PHP 过滤器			</a>
			<a target="_top" href="../php/php-filter-advanced.html">PHP 高级过滤器</a>
<a target="_top" href="../php/php-json.html">PHP JSON</a>
<br><h2 class="left"><span class="left_h2">PHP 7</span> 新特性</h2>
<a target="_top" href="../php/php7-new-features.html">PHP 7 新特性</a>
<br><h2 class="left"><span class="left_h2">PHP</span> 数据库</h2>			<a target="_top" title="PHP MySQL 简介"  href="../php/php-mysql-intro.html" >
			PHP MySQL 简介			</a>
						<a target="_top" title="PHP 连接 MySQL"  href="../php/php-mysql-connect.html" >
			PHP MySQL 连接 			</a>
						<a target="_top" title="PHP MySQL 创建数据库"  href="../php/php-mysql-create.html" >
			PHP MySQL 创建数据库			</a>
			<a target="_top" title="PHP MySQL 创建数据表" href="php-mysql-create-table.html"> PHP MySQL 创建数据表 </a>			<a target="_top" title="PHP MySQL 插入数据"  href="../php/php-mysql-insert.html" >
			PHP MySQL 插入数据			</a>
			<a target="_top" title="PHP MySQL 插入多条数据" href="php-mysql-insert-multiple.html"> PHP MySQL 插入多条数据 </a>
<a target="_top" title="PHP MySQL  预处理语句" href="php-mysql-prepared-statements.html"> PHP MySQL 预处理语句 </a>			<a target="_top" title="PHP MySQL 读取数据"  href="../php/php-mysql-select.html" >
			PHP MySQL 读取数据			</a>
						<a target="_top" title="PHP MySQL Where 子句"  href="../php/php-mysql-where.html" >
			PHP MySQL Where			</a>
						<a target="_top" title="PHP MySQL Order By 关键词"  href="../php/php-mysql-order-by.html" >
			PHP MySQL Order By			</a>
						<a target="_top" title="PHP MySQL Update"  href="../php/php-mysql-update.html" >
			PHP MySQL Update			</a>
						<a target="_top" title="PHP MySQL Delete"  href="../php/php-mysql-delete.html" >
			PHP MySQL Delete			</a>
						<a target="_top" title="PHP 数据库 ODBC"  href="../php/php-db-odbc.html" >
			PHP ODBC			</a>
			<br><h2 class="left"><span class="left_h2">PHP</span> XML</h2>			<a target="_top" title="PHP XML Expat 解析器"  href="../php/php-xml-parser-expat.html" >
			XML Expat Parser			</a>
						<a target="_top" title="PHP XML DOM"  href="../php/php-xml-dom.html" >
			XML DOM			</a>
						<a target="_top" title="PHP XML SimpleXML"  href="../php/php-xml-simplexml.html" >
			XML SimpleXML			</a>
			<br><h2 class="left"><span class="left_h2">PHP</span> 与 AJAX</h2>			<a target="_top" title="AJAX 简介"  href="../php/php-ajax-intro.html" >
			AJAX 简介			</a>
						<a target="_top" title="PHP &#8211; AJAX 与 PHP"  href="../php/php-ajax-php.html" >
			AJAX PHP			</a>
						<a target="_top" title="PHP 实例 AJAX 与 MySQL"  href="../php/php-ajax-database.html" >
			AJAX 数据库			</a>
						<a target="_top" title="PHP 实例 AJAX 与 XML"  href="../php/php-ajax-xml.html" >
			AJAX XML			</a>
						<a target="_top" title="PHP 实例 AJAX 实时搜索"  href="../php/php-ajax-livesearch.html" >
			AJAX  实时搜索			</a>
						<a target="_top" title="PHP 实例 AJAX RSS 阅读器"  href="../php/php-ajax-rss-reader.html" >
			AJAX RSS Reader			</a>
						<a target="_top" title="PHP 实例 AJAX 投票"  href="../php/php-ajax-poll.html" >
			AJAX 投票			</a>
			<br><h2 class="left"><span class="left_h2">PHP</span> 参考手册</h2>			<a target="_top" title="PHP 5 Array 函数"  href="../php/php-ref-array.html" >
			PHP Array			</a>
						<a target="_top" title="PHP 5 Calendar 函数"  href="../php/php-ref-calendar.html" >
			PHP Calendar			</a>
			<a target="_top" href="../php/php-ref-curl.html">PHP cURL </a>			<a target="_top" title="PHP 5 Date/Time 函数"  href="../php/php-ref-date.html" >
			PHP Date			</a>
						<a target="_top" title="PHP 5 Directory 函数"  href="../php/php-ref-directory.html" >
			PHP Directory			</a>
						<a target="_top" title="PHP Error 和 Logging 函数"  href="../php/php-ref-error.html" >
			PHP Error			</a>
						<a target="_top" title="PHP 5 Filesystem 函数"  href="../php/php-ref-filesystem.html" >
			PHP Filesystem			</a>
						<a target="_top" title="PHP Filter 函数"  href="../php/php-ref-filter.html" >
			PHP Filter			</a>
						<a target="_top" title="PHP FTP 函数"  href="../php/php-ref-ftp.html" >
			PHP FTP			</a>
						<a target="_top" title="PHP HTTP 函数"  href="../php/php-ref-http.html" >
			PHP HTTP			</a>
						<a target="_top" title="PHP Libxml 函数"  href="../php/php-ref-libxml.html" >
			PHP Libxml			</a>
						<a target="_top" title="PHP Mail 函数"  href="../php/php-ref-mail.html" >
			PHP Mail			</a>
						<a target="_top" title="PHP 5 Math 函数"  href="../php/php-ref-math.html" >
			PHP Math			</a>
						<a target="_top" title="PHP Misc. 函数"  href="../php/php-ref-misc.html" >
			PHP Misc			</a>
						<a target="_top" title="PHP 5 MySQLi 函数"  href="../php/php-ref-mysqli.html" >
			PHP MySQLi			</a>
			<a target="_top" title="PHP PDO" href="php-pdo.html"> PHP PDO </a>			<a target="_top" title="PHP 5 SimpleXML 函数"  href="../php/php-ref-simplexml.html" >
			PHP SimpleXML			</a>
						<a target="_top" title="PHP 5 String 函数"  href="../php/php-ref-string.html" >
			PHP String			</a>
						<a target="_top" title="PHP XML 函数"  href="../php/php-ref-xml.html" >
			PHP XML			</a>
						<a target="_top" title="PHP Zip File 函数"  href="../php/php-ref-zip.html" >
			PHP Zip			</a>
						<a target="_top" title="PHP 5 Timezones"  href="../php/php-ref-timezones.html" >
			PHP Timezones			</a>
						<a target="_top" title="PHP 图像处理"  href="../php/php-image-gd.html" >
			PHP 图像处理			</a>
						<a target="_top" title="PHP RESTful"  href="../php/php-restful.html" >
			PHP RESTful			</a>
						<a target="_top" title="PHP 正则表达式(PCRE)"  href="../php/php-pcre.html" >
			PHP PCRE			</a>
						<a target="_top" title="PHP 可用的函数"  href="../php/php-variable-handling-functions.html" >
			PHP 可用的函数			</a>
			<a target="_blank" title=" PHP 依赖管理工具" href="../w3cnote/composer-install-and-usage.html"> PHP Composer</a>	
		</div>
	</div>	
</div>
</div>	<div class="col middle-column">
		
	
	<div class="article">
		
		<div class="previous-next-links">
			<div class="previous-design-link"><i style="font-size:16px;" class="fa fa-arrow-left" aria-hidden="true"></i> <a href="../php/php-string.html" rel="prev"> PHP 字符串变量</a> </div>
			<div class="next-design-link"><a href="../php/php-if-else.html" rel="next"> PHP If&#8230;Else 语句</a> <i style="font-size:16px;" class="fa fa-arrow-right" aria-hidden="true"></i></div>
		</div>
<div class="article-heading-ad" style="display: block;">
<script async src=""
     crossorigin="anonymous"></script>
<!-- 728*90 固定 -->
<ins class="adsbygoogle"
     style="display:inline-block;width:728px;height:90px"
     data-ad-client="ca-pub-5751451760833794"
     data-ad-slot="2147566827"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>
		</div>
		<div class="article-body">
		
			<div class="article-intro" id="content">
			
			<h1>PHP <span class="color_h1">运算符</span>
</h1>
<hr>
<p class="intro">本章节我们将讨论 PHP 中不同运算符的应用。</p>
<p class="intro">在 PHP 中，赋值运算符 <span class="marked">=</span> 用于给变量赋值。</p>
<p class="intro">在 PHP 中，算术运算符 <span class="marked">+</span> 用于把值加在一起。</p>

<hr>
<h2>PHP 算术运算符</h2>
<table class="reference">
<tr>
<th width="13%" align="left">运算符</th>
<th width="20%" align="left">名称</th>
<th width="30%" align="left">描述</th>
<th width="27%" align="left">实例</th>
<th width="10%" align="left">结果</th>
</tr>
<tr>
<td>x + y</td>
<td>加</td>
<td>x 和 y 的和</td>
<td>2 + 2</td>
<td>4</td>
</tr>
<tr>
<td>x - y</td>
<td>减</td>
<td>x 和 y 的差</td>
<td>5 - 2</td>
<td>3</td>
</tr>
<tr>
<td>x * y</td>
<td>乘</td>
<td>x 和 y 的积</td>
<td>5 * 2</td>
<td>10</td>
</tr>
<tr>
<td>x / y</td>
<td>除</td>
<td>x 和 y 的商</td>
<td>15 / 5</td>
<td>3</td>
</tr>
<tr>
<td>x % y</td>
<td>模（除法的余数）</td>
<td>x 除以 y 的余数</td>
<td>5 % 2<br>10 % 8<br>10 % 2</td>
<td>1<br>2<br>0</td>
</tr>

<tr>
<td>-x</td>
<td>设置负数</td>
<td>取 x 的相反符号</td>
<td><pre>&lt;?php
$x = 2;
echo -$x;
?&gt;</pre></td>
<td>-2</td>
</tr>

<tr>
<td>~x</td>
<td>取反</td>
<td><p>x 取反，按二进制位进行"取反"运算。运算规则：</p>

<pre>~1=-2;   
~0=-1;</pre></td>
<td><pre>&lt;?php
$x = 2;
echo ~$x;
?&gt;</pre></td>
<td>-3 </td>
</tr>
<tr>
<td>a . b </td>
<td>并置</td>
<td>连接两个字符串</td>
<td>"Hi" . "Ha"</td>
<td>HiHa</td>
</tr>
</table>
<p>以下实例演示了使用不同算术运算符得到的不同结果：</p>
<div class="example">
<h2 class="example">实例</h2>
<div class="example_code">
<div class="hl-main"><span class="hl-inlinetags">&lt;?php</span><span class="hl-code"> 
</span><span class="hl-var">$x</span><span class="hl-code">=</span><span class="hl-number">10</span><span class="hl-code">; 
</span><span class="hl-var">$y</span><span class="hl-code">=</span><span class="hl-number">6</span><span class="hl-code">;
</span><span class="hl-reserved">echo</span><span class="hl-code"> </span><span class="hl-brackets">(</span><span class="hl-var">$x</span><span class="hl-code"> + </span><span class="hl-var">$y</span><span class="hl-brackets">)</span><span class="hl-code">; </span><span class="hl-comment">//</span><span class="hl-comment"> 输出16</span><span class="hl-comment"></span><span class="hl-code">
</span><span class="hl-reserved">echo</span><span class="hl-code"> </span><span class="hl-quotes">'</span><span class="hl-string">&lt;br&gt;</span><span class="hl-quotes">'</span><span class="hl-code">;  </span><span class="hl-comment">//</span><span class="hl-comment"> 换行</span><span class="hl-comment"></span><span class="hl-code">
 
</span><span class="hl-reserved">echo</span><span class="hl-code"> </span><span class="hl-brackets">(</span><span class="hl-var">$x</span><span class="hl-code"> - </span><span class="hl-var">$y</span><span class="hl-brackets">)</span><span class="hl-code">; </span><span class="hl-comment">//</span><span class="hl-comment"> 输出4</span><span class="hl-comment"></span><span class="hl-code">
</span><span class="hl-reserved">echo</span><span class="hl-code"> </span><span class="hl-quotes">'</span><span class="hl-string">&lt;br&gt;</span><span class="hl-quotes">'</span><span class="hl-code">;  </span><span class="hl-comment">//</span><span class="hl-comment"> 换行</span><span class="hl-comment"></span><span class="hl-code">
 
</span><span class="hl-reserved">echo</span><span class="hl-code"> </span><span class="hl-brackets">(</span><span class="hl-var">$x</span><span class="hl-code"> * </span><span class="hl-var">$y</span><span class="hl-brackets">)</span><span class="hl-code">; </span><span class="hl-comment">//</span><span class="hl-comment"> 输出60</span><span class="hl-comment"></span><span class="hl-code">
</span><span class="hl-reserved">echo</span><span class="hl-code"> </span><span class="hl-quotes">'</span><span class="hl-string">&lt;br&gt;</span><span class="hl-quotes">'</span><span class="hl-code">;  </span><span class="hl-comment">//</span><span class="hl-comment"> 换行</span><span class="hl-comment"></span><span class="hl-code">
 
</span><span class="hl-reserved">echo</span><span class="hl-code"> </span><span class="hl-brackets">(</span><span class="hl-var">$x</span><span class="hl-code"> / </span><span class="hl-var">$y</span><span class="hl-brackets">)</span><span class="hl-code">; </span><span class="hl-comment">//</span><span class="hl-comment"> 输出1.6666666666667</span><span class="hl-comment"></span><span class="hl-code">
</span><span class="hl-reserved">echo</span><span class="hl-code"> </span><span class="hl-quotes">'</span><span class="hl-string">&lt;br&gt;</span><span class="hl-quotes">'</span><span class="hl-code">;  </span><span class="hl-comment">//</span><span class="hl-comment"> 换行</span><span class="hl-comment"></span><span class="hl-code">
 
</span><span class="hl-reserved">echo</span><span class="hl-code"> </span><span class="hl-brackets">(</span><span class="hl-var">$x</span><span class="hl-code"> % </span><span class="hl-var">$y</span><span class="hl-brackets">)</span><span class="hl-code">; </span><span class="hl-comment">//</span><span class="hl-comment"> 输出4</span><span class="hl-comment"></span><span class="hl-code">
</span><span class="hl-reserved">echo</span><span class="hl-code"> </span><span class="hl-quotes">'</span><span class="hl-string">&lt;br&gt;</span><span class="hl-quotes">'</span><span class="hl-code">;  </span><span class="hl-comment">//</span><span class="hl-comment"> 换行</span><span class="hl-comment"></span><span class="hl-code">
 
</span><span class="hl-reserved">echo</span><span class="hl-code"> -</span><span class="hl-var">$x</span><span class="hl-code">;
</span><span class="hl-inlinetags">?&gt;</span></div>
</div>
<br><a target="_blank" class="showbtn" href="../try/showphp.php?filename=demo_operator_arithmetic" rel="noopener noreferrer">尝试一下 »</a>
</div>
<p>PHP7+ 版本新增整除运算符 <strong>intdiv()</strong>，该函数返回值为第一个参数除于第二个参数的值并取整（向下取整），使用实例：</p>
<div class="example"> 
<h2 class="example">实例</h2> 
<div class="example_code">
<div class="hl-main"><span class="hl-inlinetags">&lt;?php</span><span class="hl-code">
</span><span class="hl-identifier">var_dump</span><span class="hl-brackets">(</span><span class="hl-identifier">intdiv</span><span class="hl-brackets">(</span><span class="hl-number">10</span><span class="hl-code">, </span><span class="hl-number">3</span><span class="hl-brackets">)</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-inlinetags">?&gt;</span></div>
</div></div><p>
以上实例会输出：</p>
<pre>
int(3)
</pre>
<hr>
<h2>PHP 赋值运算符</h2>
<p>在 PHP 中，基本的赋值运算符是 <span class="marked">=</span>。它意味着左操作数被设置为右侧表达式的值。也就是说，<span class="marked">$x = 5</span> 的值是 5。</p>
<table class="reference">
<tr>
<th width="13%" align="left">运算符</th>
<th width="20%" align="left">等同于</th>
<th width="67%" align="left">描述</th>
</tr>
<tr>
<td>x = y</td>
<td>x = y</td>
<td>左操作数被设置为右侧表达式的值</td>
</tr>
<tr>
<td>x += y</td>
<td>x = x + y</td>
<td>加</td>
</tr>
<tr>
<td>x -= y</td>
<td>x = x - y</td>
<td>减</td>
</tr>
<tr>
<td>x *= y</td>
<td>x = x * y</td>
<td>乘</td>
</tr>
<tr>
<td>x /= y</td>
<td>x = x / y</td>
<td>除</td>
</tr>
<tr>
<td>x %= y</td>
<td>x = x % y</td>
<td>模（除法的余数）</td>
</tr>
<tr>
<td>a .= b</td>
<td>a = a . b</td>
<td>连接两个字符串</td>
</tr>
</table>
<p>以下实例演示了使用不同赋值运算符得到的不同结果：</p>
<div class="example">
<h2 class="example">实例</h2>
<div class="example_code">
<div class="hl-main"><span class="hl-inlinetags">&lt;?php</span><span class="hl-code"> 
</span><span class="hl-var">$x</span><span class="hl-code">=</span><span class="hl-number">10</span><span class="hl-code">; 
</span><span class="hl-reserved">echo</span><span class="hl-code"> </span><span class="hl-var">$x</span><span class="hl-code">; </span><span class="hl-comment">//</span><span class="hl-comment"> 输出10</span><span class="hl-comment"></span><span class="hl-code">
 
</span><span class="hl-var">$y</span><span class="hl-code">=</span><span class="hl-number">20</span><span class="hl-code">; 
</span><span class="hl-var">$y</span><span class="hl-code"> += </span><span class="hl-number">100</span><span class="hl-code">;
</span><span class="hl-reserved">echo</span><span class="hl-code"> </span><span class="hl-var">$y</span><span class="hl-code">; </span><span class="hl-comment">//</span><span class="hl-comment"> 输出120</span><span class="hl-comment"></span><span class="hl-code">
 
</span><span class="hl-var">$z</span><span class="hl-code">=</span><span class="hl-number">50</span><span class="hl-code">;
</span><span class="hl-var">$z</span><span class="hl-code"> -= </span><span class="hl-number">25</span><span class="hl-code">;
</span><span class="hl-reserved">echo</span><span class="hl-code"> </span><span class="hl-var">$z</span><span class="hl-code">; </span><span class="hl-comment">//</span><span class="hl-comment"> 输出25</span><span class="hl-comment"></span><span class="hl-code">
 
</span><span class="hl-var">$i</span><span class="hl-code">=</span><span class="hl-number">5</span><span class="hl-code">;
</span><span class="hl-var">$i</span><span class="hl-code"> *= </span><span class="hl-number">6</span><span class="hl-code">;
</span><span class="hl-reserved">echo</span><span class="hl-code"> </span><span class="hl-var">$i</span><span class="hl-code">; </span><span class="hl-comment">//</span><span class="hl-comment"> 输出30</span><span class="hl-comment"></span><span class="hl-code">
 
</span><span class="hl-var">$j</span><span class="hl-code">=</span><span class="hl-number">10</span><span class="hl-code">;
</span><span class="hl-var">$j</span><span class="hl-code"> /= </span><span class="hl-number">5</span><span class="hl-code">;
</span><span class="hl-reserved">echo</span><span class="hl-code"> </span><span class="hl-var">$j</span><span class="hl-code">; </span><span class="hl-comment">//</span><span class="hl-comment"> 输出2</span><span class="hl-comment"></span><span class="hl-code">
 
</span><span class="hl-var">$k</span><span class="hl-code">=</span><span class="hl-number">15</span><span class="hl-code">;
</span><span class="hl-var">$k</span><span class="hl-code"> %= </span><span class="hl-number">4</span><span class="hl-code">;
</span><span class="hl-reserved">echo</span><span class="hl-code"> </span><span class="hl-var">$k</span><span class="hl-code">; </span><span class="hl-comment">//</span><span class="hl-comment"> 输出3</span><span class="hl-comment"></span><span class="hl-code">
</span><span class="hl-inlinetags">?&gt;</span></div></div>
<br><a target="_blank" class="showbtn" href="../try/showphp.php?filename=demo_operator_assignment" rel="noopener noreferrer">尝试一下 »</a>
</div>
<p>以下实例演示了使用不同字符串运算符得到的相同结果：</p>
<div class="example">
<h2 class="example">实例</h2>
<div class="example_code">
<div class="hl-main"><span class="hl-inlinetags">&lt;?php</span><span class="hl-code">
</span><span class="hl-var">$a</span><span class="hl-code"> = </span><span class="hl-quotes">&quot;</span><span class="hl-string">Hello</span><span class="hl-quotes">&quot;</span><span class="hl-code">;
</span><span class="hl-var">$b</span><span class="hl-code"> = </span><span class="hl-var">$a</span><span class="hl-code"> . </span><span class="hl-quotes">&quot;</span><span class="hl-string"> world!</span><span class="hl-quotes">&quot;</span><span class="hl-code">;
</span><span class="hl-reserved">echo</span><span class="hl-code"> </span><span class="hl-var">$b</span><span class="hl-code">; </span><span class="hl-comment">//</span><span class="hl-comment"> 输出Hello world! </span><span class="hl-comment"></span><span class="hl-code">
 
</span><span class="hl-var">$x</span><span class="hl-code">=</span><span class="hl-quotes">&quot;</span><span class="hl-string">Hello</span><span class="hl-quotes">&quot;</span><span class="hl-code">;
</span><span class="hl-var">$x</span><span class="hl-code"> .= </span><span class="hl-quotes">&quot;</span><span class="hl-string"> world!</span><span class="hl-quotes">&quot;</span><span class="hl-code">;
</span><span class="hl-reserved">echo</span><span class="hl-code"> </span><span class="hl-var">$x</span><span class="hl-code">; </span><span class="hl-comment">//</span><span class="hl-comment"> 输出Hello world! </span><span class="hl-comment"></span><span class="hl-code">
</span><span class="hl-inlinetags">?&gt;</span></div>
</div>
<br><a target="_blank" class="showbtn" href="../try/showphp.php?filename=demo_operator_string" rel="noopener noreferrer">尝试一下 »</a>
</div>
<hr>
<h2>PHP 递增/递减运算符</h2>
<table class="reference" id="table1">
<tr>
<th width="13%" align="left">运算符</th>
<th width="20%" align="left">名称</th>
<th width="67%" align="left">描述</th>
</tr>
<tr>
<td>++ x</td>
<td>预递增</td>
<td>x 加 1，然后返回 x</td>
</tr>
<tr>
<td>x ++</td>
<td>后递增</td>
<td>返回 x，然后 x 加 1</td>
</tr>
<tr>
<td>-- x</td>
<td>预递减</td>
<td>x 减 1，然后返回 x</td>
</tr>
<tr>
<td>x --</td>
<td>后递减</td>
<td>返回 x，然后 x 减 1</td>
</tr>
</table>

<p>以下实例演示了使用递增/递减运算符得到的结果：</p>
<div class="example">
<h2 class="example">实例</h2>
<div class="example_code">
<div class="hl-main"><span class="hl-inlinetags">&lt;?php</span><span class="hl-code">
</span><span class="hl-var">$x</span><span class="hl-code">=</span><span class="hl-number">10</span><span class="hl-code">; 
</span><span class="hl-reserved">echo</span><span class="hl-code"> ++</span><span class="hl-var">$x</span><span class="hl-code">; </span><span class="hl-comment">//</span><span class="hl-comment"> 输出11</span><span class="hl-comment"></span><span class="hl-code">
 
</span><span class="hl-var">$y</span><span class="hl-code">=</span><span class="hl-number">10</span><span class="hl-code">; 
</span><span class="hl-reserved">echo</span><span class="hl-code"> </span><span class="hl-var">$y</span><span class="hl-code">++; </span><span class="hl-comment">//</span><span class="hl-comment"> 输出10</span><span class="hl-comment"></span><span class="hl-code">
 
</span><span class="hl-var">$z</span><span class="hl-code">=</span><span class="hl-number">5</span><span class="hl-code">;
</span><span class="hl-reserved">echo</span><span class="hl-code"> --</span><span class="hl-var">$z</span><span class="hl-code">; </span><span class="hl-comment">//</span><span class="hl-comment"> 输出4</span><span class="hl-comment"></span><span class="hl-code">
 
</span><span class="hl-var">$i</span><span class="hl-code">=</span><span class="hl-number">5</span><span class="hl-code">;
</span><span class="hl-reserved">echo</span><span class="hl-code"> </span><span class="hl-var">$i</span><span class="hl-code">--; </span><span class="hl-comment">//</span><span class="hl-comment"> 输出5</span><span class="hl-comment"></span><span class="hl-code">
</span><span class="hl-inlinetags">?&gt;</span></div></div>
<br><a target="_blank" class="showbtn" href="../try/showphp.php?filename=demo_operator_increment" rel="noopener noreferrer">尝试一下 »</a>
</div>
<hr>
<h2>PHP 比较运算符</h2>
<p>比较操作符可以让您比较两个值：</p>
<table class="reference">
<tr>
<th width="13%" align="left">运算符</th>
<th width="20%" align="left">名称</th>
<th width="37%" align="left">描述</th>
<th width="30%" align="left">实例</th>
</tr>
<tr>
<td>x == y</td>
<td>等于</td>
<td>如果 x 等于 y，则返回 true</td>
<td>5==8 返回 false</td>
</tr>
<tr>
<td>x === y</td>
<td>绝对等于</td>
<td>如果 x 等于 y，且它们类型相同，则返回 true</td>
<td>5==="5" 返回 false</td>
</tr>
<tr>
<td>x != y</td>
<td>不等于</td>
<td>如果 x 不等于 y，则返回 true</td>
<td>5!=8 返回 true</td>
</tr>
<tr>
<td>x &lt;&gt; y</td>
<td>不等于</td>
<td>如果 x 不等于 y，则返回 true</td>
<td>5&lt;&gt;8 返回 true</td>
</tr>
<tr>
<td>x !== y</td>
<td>不绝对等于</td>
<td>如果 x 不等于 y，或它们类型不相同，则返回 true</td>
<td>5!=="5" 返回 true</td>
</tr>
<tr>
<td>x &gt; y</td>
<td>大于</td>
<td>如果 x 大于 y，则返回 true</td>
<td>5&gt;8 返回 false</td>
</tr>
<tr>
<td>x &lt; y</td>
<td>小于</td>
<td>如果 x 小于 y，则返回 true</td>
<td>5&lt;8 返回 true</td>
</tr>
<tr>
<td>x &gt;= y</td>
<td>大于等于</td>
<td>如果 x 大于或者等于 y，则返回 true</td>
<td>5&gt;=8 返回 false</td>
</tr>
<tr>
<td>x &lt;= y</td>
<td>小于等于</td>
<td>如果 x 小于或者等于 y，则返回 true</td>
<td>5&lt;=8 返回 true</td>
</tr>
</table><p>以下实例演示了使用一些比较运算符得到的不同结果：</p>
<div class="example">
<h2 class="example">实例</h2>
<div class="example_code">
<div class="hl-main"><span class="hl-inlinetags">&lt;?php</span><span class="hl-code">
</span><span class="hl-var">$x</span><span class="hl-code">=</span><span class="hl-number">100</span><span class="hl-code">; 
</span><span class="hl-var">$y</span><span class="hl-code">=</span><span class="hl-quotes">&quot;</span><span class="hl-string">100</span><span class="hl-quotes">&quot;</span><span class="hl-code">;
 
</span><span class="hl-identifier">var_dump</span><span class="hl-brackets">(</span><span class="hl-var">$x</span><span class="hl-code"> == </span><span class="hl-var">$y</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-reserved">echo</span><span class="hl-code"> </span><span class="hl-quotes">&quot;</span><span class="hl-string">&lt;br&gt;</span><span class="hl-quotes">&quot;</span><span class="hl-code">;
</span><span class="hl-identifier">var_dump</span><span class="hl-brackets">(</span><span class="hl-var">$x</span><span class="hl-code"> === </span><span class="hl-var">$y</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-reserved">echo</span><span class="hl-code"> </span><span class="hl-quotes">&quot;</span><span class="hl-string">&lt;br&gt;</span><span class="hl-quotes">&quot;</span><span class="hl-code">;
</span><span class="hl-identifier">var_dump</span><span class="hl-brackets">(</span><span class="hl-var">$x</span><span class="hl-code"> != </span><span class="hl-var">$y</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-reserved">echo</span><span class="hl-code"> </span><span class="hl-quotes">&quot;</span><span class="hl-string">&lt;br&gt;</span><span class="hl-quotes">&quot;</span><span class="hl-code">;
</span><span class="hl-identifier">var_dump</span><span class="hl-brackets">(</span><span class="hl-var">$x</span><span class="hl-code"> !== </span><span class="hl-var">$y</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-reserved">echo</span><span class="hl-code"> </span><span class="hl-quotes">&quot;</span><span class="hl-string">&lt;br&gt;</span><span class="hl-quotes">&quot;</span><span class="hl-code">;
 
</span><span class="hl-var">$a</span><span class="hl-code">=</span><span class="hl-number">50</span><span class="hl-code">;
</span><span class="hl-var">$b</span><span class="hl-code">=</span><span class="hl-number">90</span><span class="hl-code">;
 
</span><span class="hl-identifier">var_dump</span><span class="hl-brackets">(</span><span class="hl-var">$a</span><span class="hl-code"> &gt; </span><span class="hl-var">$b</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-reserved">echo</span><span class="hl-code"> </span><span class="hl-quotes">&quot;</span><span class="hl-string">&lt;br&gt;</span><span class="hl-quotes">&quot;</span><span class="hl-code">;
</span><span class="hl-identifier">var_dump</span><span class="hl-brackets">(</span><span class="hl-var">$a</span><span class="hl-code"> &lt; </span><span class="hl-var">$b</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-inlinetags">?&gt;</span></div></div>
<br><a target="_blank" class="showbtn" href="../try/showphp.php?filename=demo_operator_comparison" rel="noopener noreferrer">尝试一下 »</a>
</div>
<hr>
<h2>PHP 逻辑运算符</h2>
<table class="reference">
<tr>
<th width="13%" align="left">运算符</th>
<th width="20%" align="left">名称</th>
<th width="37%" align="left">描述</th>
<th width="30%" align="left">实例</th>
</tr>
<tr>
<td>x and y</td>
<td>与</td>
<td>如果 x 和 y 都为 true，则返回 true</td>
<td> x=6<br>y=3
<br>
(x &lt; 10 and y &gt; 1) 返回 true</td>
</tr>
<tr>
<td>x or y</td>
<td>或</td>
<td>如果 x 和 y 至少有一个为 true，则返回 true</td>
<td> x=6<br>y=3
<br>
(x==6 or y==5) 返回 true</td>
</tr>
<tr>
<td>x xor y</td>
<td>异或</td>
<td>如果 x 和 y 有且仅有一个为 true，则返回 true</td>
<td> x=6<br>y=3
<br>
(x==6 xor y==3) 返回 false</td>
</tr>
<tr>
<td>x &amp;&amp; y</td>
<td>与</td>
<td>如果 x 和 y 都为 true，则返回 true</td>
<td> x=6<br>y=3<br>
(x &lt; 10 &amp;&amp; y &gt; 1) 返回 true</td>
</tr>
<tr>
<td>x || y</td>
<td>或</td>
<td>如果 x 和 y 至少有一个为 true，则返回 true</td>
<td> x=6<br>y=3<br>
(x==5 || y==5) 返回 false</td>
</tr>
<tr>
<td>! x</td>
<td>非</td>
<td>如果 x 不为 true，则返回 true</td>
<td> x=6<br>y=3<br>
!(x==y) 返回 true</td>
</tr>
</table>
<hr>
<h2>PHP 数组运算符</h2>
<table class="reference" id="table2">
<tr>
<th width="13%" align="left">运算符</th>
<th width="20%" align="left">名称</th>
<th width="67%" align="left">描述</th>
</tr>
<tr>
<td>x + y</td>
<td>集合</td>
<td>x 和 y 的集合</td>
</tr>
<tr>
<td>x == y</td>
<td>相等</td>
<td>如果 x 和 y 具有相同的键/值对，则返回 true</td>
</tr>
<tr>
<td>x === y</td>
<td>恒等</td>
<td>如果 x 和 y 具有相同的键/值对，且顺序相同类型相同，则返回 true</td>
</tr>
<tr>
<td>x != y</td>
<td>不相等</td>
<td>如果 x 不等于 y，则返回 true</td>
</tr>
<tr>
<td>x &lt;&gt; y</td>
<td>不相等</td>
<td>如果 x 不等于 y，则返回 true</td>
</tr>
<tr>
<td>x !== y</td>
<td>不恒等</td>
<td>如果 x 不等于 y，则返回 true</td>
</tr>
</table>
<p>以下实例演示了使用一些数组运算符得到的不同结果：</p>
<div class="example">
<h2 class="example">实例</h2>
<div class="example_code">
<div class="hl-main"><span class="hl-inlinetags">&lt;?php</span><span class="hl-code">
</span><span class="hl-var">$x</span><span class="hl-code"> = </span><span class="hl-reserved">array</span><span class="hl-brackets">(</span><span class="hl-quotes">&quot;</span><span class="hl-string">a</span><span class="hl-quotes">&quot;</span><span class="hl-code"> =&gt; </span><span class="hl-quotes">&quot;</span><span class="hl-string">red</span><span class="hl-quotes">&quot;</span><span class="hl-code">, </span><span class="hl-quotes">&quot;</span><span class="hl-string">b</span><span class="hl-quotes">&quot;</span><span class="hl-code"> =&gt; </span><span class="hl-quotes">&quot;</span><span class="hl-string">green</span><span class="hl-quotes">&quot;</span><span class="hl-brackets">)</span><span class="hl-code">; 
</span><span class="hl-var">$y</span><span class="hl-code"> = </span><span class="hl-reserved">array</span><span class="hl-brackets">(</span><span class="hl-quotes">&quot;</span><span class="hl-string">c</span><span class="hl-quotes">&quot;</span><span class="hl-code"> =&gt; </span><span class="hl-quotes">&quot;</span><span class="hl-string">blue</span><span class="hl-quotes">&quot;</span><span class="hl-code">, </span><span class="hl-quotes">&quot;</span><span class="hl-string">d</span><span class="hl-quotes">&quot;</span><span class="hl-code"> =&gt; </span><span class="hl-quotes">&quot;</span><span class="hl-string">yellow</span><span class="hl-quotes">&quot;</span><span class="hl-brackets">)</span><span class="hl-code">; 
</span><span class="hl-var">$z</span><span class="hl-code"> = </span><span class="hl-var">$x</span><span class="hl-code"> + </span><span class="hl-var">$y</span><span class="hl-code">; </span><span class="hl-comment">//</span><span class="hl-comment"> $x 和 $y 数组合并</span><span class="hl-comment"></span><span class="hl-code">
</span><span class="hl-identifier">var_dump</span><span class="hl-brackets">(</span><span class="hl-var">$z</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-identifier">var_dump</span><span class="hl-brackets">(</span><span class="hl-var">$x</span><span class="hl-code"> == </span><span class="hl-var">$y</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-identifier">var_dump</span><span class="hl-brackets">(</span><span class="hl-var">$x</span><span class="hl-code"> === </span><span class="hl-var">$y</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-identifier">var_dump</span><span class="hl-brackets">(</span><span class="hl-var">$x</span><span class="hl-code"> != </span><span class="hl-var">$y</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-identifier">var_dump</span><span class="hl-brackets">(</span><span class="hl-var">$x</span><span class="hl-code"> &lt;&gt; </span><span class="hl-var">$y</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-identifier">var_dump</span><span class="hl-brackets">(</span><span class="hl-var">$x</span><span class="hl-code"> !== </span><span class="hl-var">$y</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-inlinetags">?&gt;</span></div>
</div>
<br><a target="_blank" class="showbtn" href="../try/showphp.php?filename=demo_operator_array" rel="noopener noreferrer">尝试一下 »</a>
</div>
<hr>
<h2>三元运算符</h2>
<p>另一个条件运算符是"?:"（或三元）运算符 。</p>
<h3>语法格式</h3>
<pre>
(expr1) ? (expr2) : (expr3) 
</pre>
<p>对 expr1 求值为 TRUE 时的值为 expr2，在 expr1 求值为 FALSE 时的值为 expr3。</p>
<p>自 PHP 5.3 起，可以省略三元运算符中间那部分。表达式 expr1 ?: expr3 在 expr1 求值为 TRUE 时返回 expr1，否则返回 expr3。</p>
<h3>实例</h3>
<p>以下实例中通过判断 $_GET 请求中含有 user 值，如果有返回 $_GET['user']，否则返回 nobody：</p>
<div class="example"> 
<h2 class="example">实例</h2> 
<div class="example_code">
<div class="hl-main"><span class="hl-inlinetags">&lt;?php</span><span class="hl-code">
</span><span class="hl-comment">//</span><span class="hl-comment"> 普通写法</span><span class="hl-comment"></span><span class="hl-code">
</span><span class="hl-var">$username</span><span class="hl-code"> = </span><span class="hl-reserved">isset</span><span class="hl-brackets">(</span><span class="hl-var">$_GET</span><span class="hl-brackets">[</span><span class="hl-quotes">'</span><span class="hl-string">user</span><span class="hl-quotes">'</span><span class="hl-brackets">]</span><span class="hl-brackets">)</span><span class="hl-code"> ? </span><span class="hl-var">$_GET</span><span class="hl-brackets">[</span><span class="hl-quotes">'</span><span class="hl-string">user</span><span class="hl-quotes">'</span><span class="hl-brackets">]</span><span class="hl-code"> : </span><span class="hl-quotes">'</span><span class="hl-string">nobody</span><span class="hl-quotes">'</span><span class="hl-code">;
</span><span class="hl-reserved">echo</span><span class="hl-code"> </span><span class="hl-var">$username</span><span class="hl-code">, </span><span class="hl-identifier">PHP_EOL</span><span class="hl-code">;
 
</span><span class="hl-comment">//</span><span class="hl-comment"> PHP 5.3+ 版本写法</span><span class="hl-comment"></span><span class="hl-code">
</span><span class="hl-var">$username</span><span class="hl-code"> = </span><span class="hl-var">$_GET</span><span class="hl-brackets">[</span><span class="hl-quotes">'</span><span class="hl-string">user</span><span class="hl-quotes">'</span><span class="hl-brackets">]</span><span class="hl-code"> ?: </span><span class="hl-quotes">'</span><span class="hl-string">nobody</span><span class="hl-quotes">'</span><span class="hl-code">;
</span><span class="hl-reserved">echo</span><span class="hl-code"> </span><span class="hl-var">$username</span><span class="hl-code">, </span><span class="hl-identifier">PHP_EOL</span><span class="hl-code">;
</span><span class="hl-inlinetags">?&gt;</span></div>
</div></div>

<p><b>注意：</b><span class="marked">PHP_EOL</span> 是一个换行符，兼容更大平台。</p>
<p>在 PHP7+ 版本多了一个 NULL 合并运算符 <span class="marked">??</span>，实例如下：</p>
<div class="example"> 
<h2 class="example">实例</h2> 
<div class="example_code">
<div class="hl-main"><span class="hl-inlinetags">&lt;?php</span><span class="hl-code">
</span><span class="hl-comment">//</span><span class="hl-comment"> 如果 $_GET['user'] 不存在返回 'nobody'，否则返回 $_GET['user'] 的值</span><span class="hl-comment"></span><span class="hl-code">
</span><span class="hl-var">$username</span><span class="hl-code"> = </span><span class="hl-var">$_GET</span><span class="hl-brackets">[</span><span class="hl-quotes">'</span><span class="hl-string">user</span><span class="hl-quotes">'</span><span class="hl-brackets">]</span><span class="hl-code"> ?? </span><span class="hl-quotes">'</span><span class="hl-string">nobody</span><span class="hl-quotes">'</span><span class="hl-code">;
</span><span class="hl-comment">//</span><span class="hl-comment"> 类似的三元运算符</span><span class="hl-comment"></span><span class="hl-code">
</span><span class="hl-var">$username</span><span class="hl-code"> = </span><span class="hl-reserved">isset</span><span class="hl-brackets">(</span><span class="hl-var">$_GET</span><span class="hl-brackets">[</span><span class="hl-quotes">'</span><span class="hl-string">user</span><span class="hl-quotes">'</span><span class="hl-brackets">]</span><span class="hl-brackets">)</span><span class="hl-code"> ? </span><span class="hl-var">$_GET</span><span class="hl-brackets">[</span><span class="hl-quotes">'</span><span class="hl-string">user</span><span class="hl-quotes">'</span><span class="hl-brackets">]</span><span class="hl-code"> : </span><span class="hl-quotes">'</span><span class="hl-string">nobody</span><span class="hl-quotes">'</span><span class="hl-code">;
</span><span class="hl-inlinetags">?&gt;</span></div>
</div></div>
<hr>
<h2>组合比较符(PHP7+)</h2>
<p>PHP7+ 支持组合比较符（combined comparison operator）也称之为太空船操作符，符号为 <span class="marked">&lt;=&gt;</span>。组合比较运算符可以轻松实现两个变量的比较，当然不仅限于数值类数据的比较。</p>
<p>语法格式如下：</p><pre>$c = $a &lt;=&gt; $b;</pre>
<p>解析如下：</p>
<ul><li>
如果<strong> $a &gt; $b</strong>, 则 <strong>$c</strong> 的值为 <strong>1</strong>。</li><li>
如果 <strong>$a == $b</strong>, 则 <strong>$c</strong> 的值为 <strong>0</strong>。</li><li>
如果 <strong>$a &lt; $b</strong>, 则 <strong>$c</strong> 的值为 <strong>-1</strong>。</li></ul>


<p>实例如下：</p>
<div class="example"> 
<h2 class="example">实例</h2> 
<div class="example_code">
<div class="hl-main"><span class="hl-inlinetags">&lt;?php</span><span class="hl-code">
</span><span class="hl-comment">//</span><span class="hl-comment"> 整型</span><span class="hl-comment"></span><span class="hl-code">
</span><span class="hl-reserved">echo</span><span class="hl-code"> </span><span class="hl-number">1</span><span class="hl-code"> &lt;=&gt; </span><span class="hl-number">1</span><span class="hl-code">; </span><span class="hl-comment">//</span><span class="hl-comment"> 0</span><span class="hl-comment"></span><span class="hl-code">
</span><span class="hl-reserved">echo</span><span class="hl-code"> </span><span class="hl-number">1</span><span class="hl-code"> &lt;=&gt; </span><span class="hl-number">2</span><span class="hl-code">; </span><span class="hl-comment">//</span><span class="hl-comment"> -1</span><span class="hl-comment"></span><span class="hl-code">
</span><span class="hl-reserved">echo</span><span class="hl-code"> </span><span class="hl-number">2</span><span class="hl-code"> &lt;=&gt; </span><span class="hl-number">1</span><span class="hl-code">; </span><span class="hl-comment">//</span><span class="hl-comment"> 1</span><span class="hl-comment"></span><span class="hl-code">
 
</span><span class="hl-comment">//</span><span class="hl-comment"> 浮点型</span><span class="hl-comment"></span><span class="hl-code">
</span><span class="hl-reserved">echo</span><span class="hl-code"> </span><span class="hl-number">1</span><span class="hl-number">.5</span><span class="hl-code"> &lt;=&gt; </span><span class="hl-number">1</span><span class="hl-number">.5</span><span class="hl-code">; </span><span class="hl-comment">//</span><span class="hl-comment"> 0</span><span class="hl-comment"></span><span class="hl-code">
</span><span class="hl-reserved">echo</span><span class="hl-code"> </span><span class="hl-number">1</span><span class="hl-number">.5</span><span class="hl-code"> &lt;=&gt; </span><span class="hl-number">2</span><span class="hl-number">.5</span><span class="hl-code">; </span><span class="hl-comment">//</span><span class="hl-comment"> -1</span><span class="hl-comment"></span><span class="hl-code">
</span><span class="hl-reserved">echo</span><span class="hl-code"> </span><span class="hl-number">2</span><span class="hl-number">.5</span><span class="hl-code"> &lt;=&gt; </span><span class="hl-number">1</span><span class="hl-number">.5</span><span class="hl-code">; </span><span class="hl-comment">//</span><span class="hl-comment"> 1</span><span class="hl-comment"></span><span class="hl-code">
 
</span><span class="hl-comment">//</span><span class="hl-comment"> 字符串</span><span class="hl-comment"></span><span class="hl-code">
</span><span class="hl-reserved">echo</span><span class="hl-code"> </span><span class="hl-quotes">&quot;</span><span class="hl-string">a</span><span class="hl-quotes">&quot;</span><span class="hl-code"> &lt;=&gt; </span><span class="hl-quotes">&quot;</span><span class="hl-string">a</span><span class="hl-quotes">&quot;</span><span class="hl-code">; </span><span class="hl-comment">//</span><span class="hl-comment"> 0</span><span class="hl-comment"></span><span class="hl-code">
</span><span class="hl-reserved">echo</span><span class="hl-code"> </span><span class="hl-quotes">&quot;</span><span class="hl-string">a</span><span class="hl-quotes">&quot;</span><span class="hl-code"> &lt;=&gt; </span><span class="hl-quotes">&quot;</span><span class="hl-string">b</span><span class="hl-quotes">&quot;</span><span class="hl-code">; </span><span class="hl-comment">//</span><span class="hl-comment"> -1</span><span class="hl-comment"></span><span class="hl-code">
</span><span class="hl-reserved">echo</span><span class="hl-code"> </span><span class="hl-quotes">&quot;</span><span class="hl-string">b</span><span class="hl-quotes">&quot;</span><span class="hl-code"> &lt;=&gt; </span><span class="hl-quotes">&quot;</span><span class="hl-string">a</span><span class="hl-quotes">&quot;</span><span class="hl-code">; </span><span class="hl-comment">//</span><span class="hl-comment"> 1</span><span class="hl-comment"></span><span class="hl-code">
</span><span class="hl-inlinetags">?&gt;</span></div>
</div></div><hr>
<h2>运算符优先级</h2>
<p>下表按照优先级从高到低列出了运算符。同一行中的运算符具有相同优先级，此时它们的结合方向决定求值顺序。</p>
<p><strong>说明</strong>：左 ＝ 从左到右，右 ＝ 从右到左。</p>
<table class="reference">
<thead>
<tr>
<th>结合方向</th>
<th>运算符</th>
<th>附加信息</th>
</tr>
</thead>
<tbody class="tbody">
<tr>
<td>无</td>
<td>clone new</td>
<td>clone 和 new</td>
</tr>
<tr>
<td>左</td>
<td>[</td>
<td><span class="function">array()</span></td>
</tr>
<tr>
<td>右</td>
<td>++ -- ~ (int) (float) (string) (array) (object) (bool) @</td>
<td>类型和递增／递减</td>
</tr>
<tr>
<td>无</td>
<td>instanceof</td>
<td>类型</td>
</tr>
<tr>
<td>右</td>
<td>!</td>
<td>逻辑运算符</td>
</tr>
<tr>
<td>左</td>
<td>* / %</td>
<td>算术运算符</td>
</tr>
<tr>
<td>左</td>
<td>+ – .</td>
<td>算术运算符和字符串运算符</td>
</tr>
<tr>
<td>左</td>
<td>&lt;&lt; &gt;&gt;</td>
<td>位运算符</td>
</tr>
<tr>
<td>无</td>
<td>== != === !== &lt;&gt;</td>
<td>比较运算符</td>
</tr>
<tr>
<td>左</td>
<td>&amp;</td>
<td>位运算符和引用</td>
</tr>
<tr>
<td>左</td>
<td>^</td>
<td>位运算符</td>
</tr>
<tr>
<td>左</td>
<td>|</td>
<td>位运算符</td>
</tr>
<tr>
<td>左</td>
<td>&amp;&amp;</td>
<td>逻辑运算符</td>
</tr>
<tr>
<td>左</td>
<td>||</td>
<td>逻辑运算符</td>
</tr>
<tr>
<td>左</td>
<td>? :</td>
<td>三元运算符</td>
</tr>
<tr>
<td>右</td>
<td>= += -= *= /= .= %= &amp;= |= ^= &lt;&lt;= &gt;&gt;= =&gt;</td>
<td>赋值运算符</td>
</tr>
<tr>
<td>左</td>
<td>and</td>
<td>逻辑运算符</td>
</tr>
<tr>
<td>左</td>
<td>xor</td>
<td>逻辑运算符</td>
</tr>
<tr>
<td>左</td>
<td>or</td>
<td>逻辑运算符</td>
</tr>
<tr>
<td>左</td>
<td>,</td>
<td>多处用到</td>
</tr>
</tbody>
</table>
<p>运算符优先级中，or 和 ||，&& 和 and 都是逻辑运算符，效果一样，但是其优先级却不一样。</p>
<div class="example">
<h2 class="example">实例</h2>
<div class="example_code">
<div class="hl-main"><span class="hl-inlinetags">&lt;?php</span><span class="hl-code">
</span><span class="hl-comment">//</span><span class="hl-comment"> 优先级： &amp;&amp;  &gt;  =  &gt;  and</span><span class="hl-comment"></span><span class="hl-code">
</span><span class="hl-comment">//</span><span class="hl-comment"> 优先级： ||  &gt;  =  &gt;  or</span><span class="hl-comment"></span><span class="hl-code">
 
</span><span class="hl-var">$a</span><span class="hl-code"> = </span><span class="hl-number">3</span><span class="hl-code">;
</span><span class="hl-var">$b</span><span class="hl-code"> = </span><span class="hl-reserved">false</span><span class="hl-code">;
</span><span class="hl-var">$c</span><span class="hl-code"> = </span><span class="hl-var">$a</span><span class="hl-code"> </span><span class="hl-reserved">or</span><span class="hl-code"> </span><span class="hl-var">$b</span><span class="hl-code">;
</span><span class="hl-identifier">var_dump</span><span class="hl-brackets">(</span><span class="hl-var">$c</span><span class="hl-brackets">)</span><span class="hl-code">;          </span><span class="hl-comment">//</span><span class="hl-comment"> 这里的 $c 为 int 值3，而不是 boolean 值 true</span><span class="hl-comment"></span><span class="hl-code">
</span><span class="hl-var">$d</span><span class="hl-code"> = </span><span class="hl-var">$a</span><span class="hl-code"> || </span><span class="hl-var">$b</span><span class="hl-code">;
</span><span class="hl-identifier">var_dump</span><span class="hl-brackets">(</span><span class="hl-var">$d</span><span class="hl-brackets">)</span><span class="hl-code">;          </span><span class="hl-comment">//</span><span class="hl-comment">这里的 $d 就是 boolean 值 true </span><span class="hl-comment"></span><span class="hl-code">
</span><span class="hl-inlinetags">?&gt;</span></div>
</div>
</div>
<p>以上实例输出结果为：</p>
<pre>
int(3)
bool(true)
</pre>
<h3>括号的使用</h3>
<p>我们通过括号的配对来明确标明运算顺序，而非靠运算符优先级和结合性来决定，通常能够增加代码的可读性。</p>
<div class="example">
<h2 class="example">实例</h2>
<div class="example_code">
<div class="hl-main"><span class="hl-inlinetags">&lt;?php</span><span class="hl-code">
</span><span class="hl-comment">//</span><span class="hl-comment"> 括号优先运算</span><span class="hl-comment"></span><span class="hl-code">
 
</span><span class="hl-var">$a</span><span class="hl-code"> = </span><span class="hl-number">1</span><span class="hl-code">;
</span><span class="hl-var">$b</span><span class="hl-code"> = </span><span class="hl-number">2</span><span class="hl-code">;
</span><span class="hl-var">$c</span><span class="hl-code"> = </span><span class="hl-number">3</span><span class="hl-code">;
</span><span class="hl-var">$d</span><span class="hl-code"> = </span><span class="hl-var">$a</span><span class="hl-code"> + </span><span class="hl-var">$b</span><span class="hl-code"> * </span><span class="hl-var">$c</span><span class="hl-code">;
</span><span class="hl-reserved">echo</span><span class="hl-code"> </span><span class="hl-var">$d</span><span class="hl-code">;
</span><span class="hl-reserved">echo</span><span class="hl-code"> </span><span class="hl-quotes">&quot;</span><span class="hl-special">\n</span><span class="hl-quotes">&quot;</span><span class="hl-code">;
</span><span class="hl-var">$e</span><span class="hl-code"> = </span><span class="hl-brackets">(</span><span class="hl-var">$a</span><span class="hl-code"> + </span><span class="hl-var">$b</span><span class="hl-brackets">)</span><span class="hl-code"> * </span><span class="hl-var">$c</span><span class="hl-code">;  </span><span class="hl-comment">//</span><span class="hl-comment"> 使用括号</span><span class="hl-comment"></span><span class="hl-code">
</span><span class="hl-reserved">echo</span><span class="hl-code"> </span><span class="hl-var">$e</span><span class="hl-code">;
</span><span class="hl-reserved">echo</span><span class="hl-code"> </span><span class="hl-quotes">&quot;</span><span class="hl-special">\n</span><span class="hl-quotes">&quot;</span><span class="hl-code">;
</span><span class="hl-inlinetags">?&gt;</span></div>
</div>
</div><p>以上实例输出结果为：</p>
<pre>
7
9
</pre>			<!-- 其他扩展 -->
						
			</div>
			
		</div>
		
		<div class="previous-next-links">
			<div class="previous-design-link"><i style="font-size:16px;" class="fa fa-arrow-left" aria-hidden="true"></i> <a href="../php/php-string.html" rel="prev"> PHP 字符串变量</a> </div>
			<div class="next-design-link"><a href="../php/php-if-else.html" rel="next"> PHP If&#8230;Else 语句</a> <i style="font-size:16px;" class="fa fa-arrow-right" aria-hidden="true"></i></div>
		</div>
		<!-- 笔记列表 -->
		<style>
.wrapper {
  /*text-transform: uppercase; */
  background: #ececec;
  color: #555;
  cursor: help;
  font-family: "Gill Sans", Impact, sans-serif;
  font-size: 20px;
  position: relative;
  text-align: center;
  width: 200px;
  -webkit-transform: translateZ(0); /* webkit flicker fix */
  -webkit-font-smoothing: antialiased; /* webkit text rendering fix */
}

.wrapper .tooltip {
  white-space: nowrap;
  font-size: 14px;
  text-align: left;
  background: #96b97d;
  bottom: 100%;
  color: #fff;
  display: block;
  left: -25px;
  margin-bottom: 15px;
  opacity: 0;
  padding: 14px;
  pointer-events: none;
  position: absolute;
  
  -webkit-transform: translateY(10px);
     -moz-transform: translateY(10px);
      -ms-transform: translateY(10px);
       -o-transform: translateY(10px);
          transform: translateY(10px);
  -webkit-transition: all .25s ease-out;
     -moz-transition: all .25s ease-out;
      -ms-transition: all .25s ease-out;
       -o-transition: all .25s ease-out;
          transition: all .25s ease-out;
  -webkit-box-shadow: 2px 2px 6px rgba(0, 0, 0, 0.28);
     -moz-box-shadow: 2px 2px 6px rgba(0, 0, 0, 0.28);
      -ms-box-shadow: 2px 2px 6px rgba(0, 0, 0, 0.28);
       -o-box-shadow: 2px 2px 6px rgba(0, 0, 0, 0.28);
          box-shadow: 2px 2px 6px rgba(0, 0, 0, 0.28);
}
.tooltip a {
	color:#fff;
}
/* This bridges the gap so you can mouse into the tooltip without it disappearing */
.wrapper .tooltip:before {
  bottom: -20px;
  content: " ";
  display: block;
  height: 20px;
  left: 0;
  position: absolute;
  width: 100%;
}  

/* CSS Triangles - see Trevor's post */
.wrapper .tooltip:after {
  border-left: solid transparent 10px;
  border-right: solid transparent 10px;
  border-top: solid #96b97d 10px;
  bottom: -10px;
  content: " ";
  height: 0;
  left: 20%;
  margin-left: -13px;
  position: absolute;
  width: 0;
}
.wrapper .tooltip1 {
	margin-left: 50px;
	padding-top: 0px;
}
/*
.wrapper:hover .tooltip {
  opacity: 1;
  pointer-events: auto;
  -webkit-transform: translateY(0px);
     -moz-transform: translateY(0px);
      -ms-transform: translateY(0px);
       -o-transform: translateY(0px);
          transform: translateY(0px);
}
*/
/* IE can just show/hide with no transition */
.lte8 .wrapper .tooltip {
  display: none;
}

.lte8 .wrapper:hover .tooltip {
  display: block;
}

</style>

<link rel="stylesheet" href="../0/upvotejs.css">
<script src=""></script>
<script src=""></script>
<div class="title" id="comments">
	<h2 class="">
    <div class="altblock">
				<i style="font-size:28px;margin-top: 8px;" class="fa fa-plus-square" aria-hidden="true"></i>
		    </div>
    <span class="mw-headline" id="qa_headline">7  篇笔记</span>
	<span class="mw-headline" id="user_add_note" style="float:right;line-height: 62px;padding-right: 14px;"><i class="fa fa-pencil-square-o" aria-hidden="true"></i>  写笔记</span>
    </h2>
</div>

<div id="postcomments"  style="display:none;" >
	<ol class="commentlist">
		<li class="comment byuser comment-author-tianqixin bypostauthor even thread-even depth-1" id="comment-1039"><span class="comt-f">#0</span><div class="comt-avatar wrapper"><i style="font-size:36px;" class="fa fa-user-circle" aria-hidden="true"></i><div class="tooltip"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;tianqixin</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;429***967@qq.com</p><p><i class="fa fa-external-link" aria-hidden="true"></i> <a rel="nofollow" target="_blank" href="http://www.runoob.com">&nbsp;&nbsp;参考地址</a></p></div><div id="runoobvote-id-1039" data-commid = "1039" class="upvotejs"><a class="upvote"></a> <span class="count">15</span></div></div><div class="comt-main" id="div-comment-1039"><p>一个等号 <strong>=</strong> 用于赋值，如：</p>
<pre>
$a = 5;
</pre>
<p>
两个等号 <strong>==</strong> 用于比较，值相等，类型不一定相等，如：</p>
<pre>
5==5  // 返回 true
5=="5" // 返回 true
</pre>
<p>
三个等号 <strong>===</strong> 用于绝对比较，即类型与值都要相等，如：
</p>
<pre>
5===5  // 返回 true
5==="5" // 返回 false
</pre><div class="comt-meta wrapper"><span class="comt-author"><a target="_blank" href="javascript:;">tianqixin</a><div class="tooltip tooltip1"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;tianqixin</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;429***967@qq.com</p><p><i class="fa fa-external-link" aria-hidden="true"></i> <a rel="nofollow" target="_blank" href="http://www.runoob.com">&nbsp;&nbsp;参考地址</a></p></div></span>6年前 (2017-02-26)</div></div></li><!-- #comment-## -->
<li class="comment odd alt thread-odd thread-alt depth-1" id="comment-10479"><span class="comt-f">#0</span><div class="comt-avatar wrapper"><i style="font-size:36px;" class="fa fa-user-circle" aria-hidden="true"></i><div class="tooltip"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;书小</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;106***0349@qq.com</p><p><i class="fa fa-external-link" aria-hidden="true"></i> <a rel="nofollow" target="_blank" href="http://www.51-n.com/t-4413-1-1.html">&nbsp;&nbsp;参考地址</a></p></div><div id="runoobvote-id-10479" data-commid = "10479" class="upvotejs"><a class="upvote"></a> <span class="count">9</span></div></div><div class="comt-main" id="div-comment-10479"><p>组合比较运算符又名太空船运算符，组合比较运算符可以轻松实现两个变量的比较，当然不仅限于数值类数据的比较。
</p><p>
语法是这样的：</p><pre>$c = $a &lt;=&gt; $b;</pre><p>
这句代码的意思是:</p><ul><li>
如果 $a > $b, $c 的值为 1</li><li>
如果 $a == $b, $c 的值为 0</li><li>
如果 $a < $b, $c 的值为-1</li></ul><div class="comt-meta wrapper"><span class="comt-author"><a target="_blank" href="javascript:;">书小</a><div class="tooltip tooltip1"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;书小</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;106***0349@qq.com</p><p><i class="fa fa-external-link" aria-hidden="true"></i> <a rel="nofollow" target="_blank" href="http://www.51-n.com/t-4413-1-1.html">&nbsp;&nbsp;参考地址</a></p></div></span>6年前 (2017-03-28)</div></div></li><!-- #comment-## -->
<li class="comment even thread-even depth-1" id="comment-13284"><span class="comt-f">#0</span><div class="comt-avatar wrapper"><i style="font-size:36px;" class="fa fa-user-circle" aria-hidden="true"></i><div class="tooltip"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;xiaoxie</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;211***8399@qq.com</p></div><div id="runoobvote-id-13284" data-commid = "13284" class="upvotejs"><a class="upvote"></a> <span class="count">18</span></div></div><div class="comt-main" id="div-comment-13284"><p>运算符的优先级口诀：括（号）、单（操作数）、算（术）、移（位）、关（系）；位（运算符）、逻（辑）、条（件）、赋（值）、逗（号）。</p><div class="comt-meta wrapper"><span class="comt-author"><a target="_blank" href="javascript:;">xiaoxie</a><div class="tooltip tooltip1"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;xiaoxie</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;211***8399@qq.com</p></div></span>6年前 (2017-06-24)</div></div></li><!-- #comment-## -->
<li class="comment odd alt thread-odd thread-alt depth-1" id="comment-16120"><span class="comt-f">#0</span><div class="comt-avatar wrapper"><i style="font-size:36px;" class="fa fa-user-circle" aria-hidden="true"></i><div class="tooltip"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;佚名灬小涛</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;770***785@qq.com</p></div><div id="runoobvote-id-16120" data-commid = "16120" class="upvotejs"><a class="upvote"></a> <span class="count">15</span></div></div><div class="comt-main" id="div-comment-16120"><p>分享一个例子：</p>
<pre>$c = &amp;$a; </pre>    
<p>c 是 a 的引用,也就是说 c 和 a 是同一个变量了。</p>
<p>& 是引用的意思，php 没有指针的概念。</p><div class="comt-meta wrapper"><span class="comt-author"><a target="_blank" href="javascript:;">佚名灬小涛</a><div class="tooltip tooltip1"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;佚名灬小涛</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;770***785@qq.com</p></div></span>6年前 (2017-08-10)</div></div></li><!-- #comment-## -->
<li class="comment even thread-even depth-1" id="comment-17269"><span class="comt-f">#0</span><div class="comt-avatar wrapper"><i style="font-size:36px;" class="fa fa-user-circle" aria-hidden="true"></i><div class="tooltip"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;Leo</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;206***2241@qq.com</p></div><div id="runoobvote-id-17269" data-commid = "17269" class="upvotejs"><a class="upvote"></a> <span class="count">20</span></div></div><div class="comt-main" id="div-comment-17269"><p><span class="marked">&nbsp;&lt;=&gt;</span> 太空船操作符，又称组合比较运算符，结合比较运算符。</p><p>组合比较运算符，英文叫作 combined comparison operator，符号为 <span class="marked">&lt;=&gt;</span>，它有一个形象的名字，叫作太空船操作符。组合比较运算符可以轻松实现两个变量的比较，当然不仅限于数值类数据的比较。</p><p>语法是这样的：</p><pre>$c = $a &lt;=&gt; $b;</pre><p>这句代码的意思是</p><ul><li>如果$a &gt; $b, $c 的值为1</li><li>如果$a == $b, $c 的值为0</li><li>如果$a &lt; $b, $c 的值为-1</li></ul><p>在没有太空船运算符的时候，我们只能这样写代码</p><pre>$c = $a &gt; $b ? 1 : ( $a==$b ? 0 : -1 );</pre><div class="comt-meta wrapper"><span class="comt-author"><a target="_blank" href="javascript:;">Leo</a><div class="tooltip tooltip1"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;Leo</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;206***2241@qq.com</p></div></span>6年前 (2017-09-07)</div></div></li><!-- #comment-## -->
<li class="comment odd alt thread-odd thread-alt depth-1" id="comment-56894"><span class="comt-f">#0</span><div class="comt-avatar wrapper"><i style="font-size:36px;" class="fa fa-user-circle" aria-hidden="true"></i><div class="tooltip"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;南宫晟醺</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;132***4430@qq.com</p></div><div id="runoobvote-id-56894" data-commid = "56894" class="upvotejs"><a class="upvote"></a> <span class="count">27</span></div></div><div class="comt-main" id="div-comment-56894"><p>关于数组:</p>


<pre>&lt;?php
$ly = array("id" =&gt; '1',"username" =&gt; 'ly');
$ngcx = array("id" =&gt; '2',"username" =&gt; 'ngcx');
var_dump($ly + $ngcx);
var_dump($ly == $ngcx);
var_dump($ly === $ngcx);
var_dump($ly &lt;&gt; $ngcx);
var_dump($ly != $ngcx);
var_dump($ly !== $ngcx);
$ly1 = array("id1" =&gt; '1',"username1" =&gt; 'ly1');
$ly2 = array("id2" =&gt; '2',"username2" =&gt; 'ly2');
var_dump($ly1+$ly2);
?&gt;
</pre>

<p>结果：</p>
<pre>
array(2) {
    ["id"]=&gt;
    string(1) "1"
    ["username"]=&gt;
    string(2) "ly"
  }
  bool(false)
  bool(false)
  bool(true)
  bool(true)
  bool(true)
  array(4) {
    ["id1"]=&gt;
    string(1) "1"
    ["username1"]=&gt;
    string(3) "ly1"
    ["id2"]=&gt;
    string(1) "2"
    ["username2"]=&gt;
    string(3) "ly2"
  }
</pre>
<p>其它的文章中都有，就将一个文章中没有说清楚的 <span class="marked">a+b</span> 集合（联合）单列出来。</p>

<p>如果两个数组他们的 key 值相同它的返回值会使用第一个数组的 value 值，如果其 key 值不同将会将他们拼接:</p>

<pre>&lt;?php 
$ly = array("idl" =&gt; '1',"usernamel" =&gt; 'ly');
$ngcx = array("idn" =&gt; '2',"usernamen" =&gt; 'ngcx');
var_dump($ly+$ngcx);
echo PHP_EOL;
$ly = array("id" =&gt; '1',"username" =&gt; 'ly');
$ngcx = array("id" =&gt; '2',"username" =&gt; 'ngcx');
var_dump($ly+$ngcx);
?&gt;</pre>
<p>结果：</p>

<pre>array(4) {
    ["idl"]=&gt;
    string(1) "1"
    ["usernamel"]=&gt;
    string(2) "ly"
    ["idn"]=&gt;
    string(1) "2"
    ["usernamen"]=&gt;
    string(4) "ngcx"
  }
  
  array(2) {
    ["id"]=&gt;
    string(1) "1"
    ["username"]=&gt;
    string(2) "ly"
  } 
</pre><div class="comt-meta wrapper"><span class="comt-author"><a target="_blank" href="javascript:;">南宫晟醺</a><div class="tooltip tooltip1"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;南宫晟醺</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;132***4430@qq.com</p></div></span>3年前 (2020-09-09)</div></div></li><!-- #comment-## -->
<li class="comment even thread-even depth-1" id="comment-75601"><span class="comt-f">#0</span><div class="comt-avatar wrapper"><i style="font-size:36px;" class="fa fa-user-circle" aria-hidden="true"></i><div class="tooltip"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;m01st</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;jqy***701724@gmail.com</p></div><div id="runoobvote-id-75601" data-commid = "75601" class="upvotejs"><a class="upvote"></a> <span class="count">1</span></div></div><div class="comt-main" id="div-comment-75601"><p>自 PHP8 开始，三元运算符不再具有顺序。</p>

<p>意思是如果不使用括号包裹，程序会报错:</p>

<pre>&lt;?php
$var = true ? 1 : false ? 2 : 3;
// $var = (true ? 1 : false) ? 2 : 3;可以执行
echo $var;
?&gt;
// 程序是不合法的</pre><div class="comt-meta wrapper"><span class="comt-author"><a target="_blank" href="javascript:;">m01st</a><div class="tooltip tooltip1"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;m01st</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;jqy***701724@gmail.com</p></div></span>7个月前 (10-04)</div></div></li><!-- #comment-## -->
	</ol>
	<div class="pagenav">
			</div>
</div>
<div id="respond" class="no_webshot"> 
		<div class="comment-signarea" style="display:none; padding: 20px 20px;"> 
	<h3 class="text-muted" id="share_code" style="color: #799961;"><i class="fa fa-pencil-square-o" aria-hidden="true"></i> 点我分享笔记</h3>
	<!--
	<p style="font-size:14px;">笔记需要是本篇文章的内容扩展！</p><br>
	<p style="font-size:12px;"><a href="../tougao" target="_blank">文章投稿，可点击这里</a></p>
	<p style="font-size:14px;"><a href="../w3cnote/runoob-user-test-intro.html#invite" target="_blank">注册邀请码获取方式</a></p>
		<h3 class="text-muted"><i class="fa fa-info-circle" aria-hidden="true"></i> 分享笔记前必须<a href="javascript:;" class="runoob-pop">登录</a>！</h3>
		<p><a href="../w3cnote/runoob-user-test-intro.html#invite" target="_blank">注册邀请码获取方式</a></p>-->
	</div>
		
	<form action="/wp-content/themes/runoob/option/addnote.php" method="post" id="commentform" style="display:none;">
		<div class="comt">
			<div class="comt-title">
				<i style="font-size:36px;" class="fa fa-user-circle" aria-hidden="true"></i>				<p><a id="cancel-comment-reply-link" href="javascript:;">取消</a></p>
			</div>
			<div class="comt-box">
			<div id="mded"></div>
			
				<div class="comt-ctrl">
					<div class="comt-tips"><input type='hidden' name='comment_post_ID' value='660' id='comment_post_ID' />
<input type='hidden' name='comment_parent' id='comment_parent' value='0' />
</div>
					<button type="submit" name="submit" id="submit" tabindex="5"><i class="fa fa-pencil" aria-hidden="true"></i> 分享笔记</button>
				</div>
			</div>
		
				
					<div class="comt-comterinfo"> 
						<ul id="comment-author-info">
							<li class="form-inline"><label class="hide" for="author">昵称</label><input class="ipt" type="text" name="author" id="author" value="" tabindex="2" placeholder="昵称"><span class="text-muted">昵称 (必填)</span></li>
							<li class="form-inline"><label class="hide" for="email">邮箱</label><input class="ipt" type="text" name="email" id="email" value="" tabindex="3" placeholder="邮箱"><span class="text-muted">邮箱 (必填)</span></li>
							<li class="form-inline"><label class="hide" for="url">引用地址</label><input class="ipt" type="text" name="url" id="url" value="" tabindex="4" placeholder="引用地址"><span class="text-muted">引用地址</span></li>
						</ul>
					</div>
				
			
		</div>

	</form>
	</div>
<script type="text/javascript">
$(function() {
	//初始化编辑器
	
	var editor = new Simditor({
	  textarea: $('#mded'),
	  placeholder: '写笔记...',
	  upload:false,
	 // upload: {url:'/api/comment_upload_file.php',params: null,fileKey: 'upload_file',connectionCount: 1,leaveConfirm: '文件正在上传，您确定离开?'},
	  defaultImage: 'https://www.runoob.com/images/logo.png',
	  codeLanguages: '',
	  autosave: 'editor-content',
	  toolbar: [  'bold','code','ul','ol','image' ]
	});
	editor.on('selectionchanged', function() {
		$(".code-popover").hide();
	});

	// 提交数据
	$("#share_code").click(function() {
		$(".comment-signarea").hide();
		$("#commentform").show();
		
	});
	$("#user_add_note").click(function() {
		$(".comment-signarea").hide();
		$("#commentform").show();
		$('html, body').animate({
       	    scrollTop: $("#respond").offset().top
    	}, 200);
	});

	// 提交笔记
	var commentform=$('#commentform');
	commentform.prepend('<div id="comment-status" style="display:none;" ></div>');
	var statusdiv=$('#comment-status');
	
	commentform.submit(function(e){
		e.preventDefault();
		var noteContent = editor.getValue();
		// console.log(noteContent);
		noteContent = noteContent.replace(/<pre><code>/g,"<pre>");
		noteContent = noteContent.replace(/<\/code><\/pre>/g,"</pre>");
		
		// 系列化表单数据
		var comment_parent = 0;
		var is_user_logged_in = $("#is_user_logged_in").val();
		var comment_post_ID =  660;
		var _wp_unfiltered_html_comment = $("#_wp_unfiltered_html_comment").val();
		var comment = noteContent;
		var author = $("#author").val();
		var url = $("#url").val();
		var email = $("#email").val();
		if(isBlank(author) && is_user_logged_in==0) {
			statusdiv.html('<p  class="ajax-error">请输入昵称！</p>').show();
		} else if(isBlank(email)  && is_user_logged_in==0) {
			statusdiv.html('<p  class="ajax-error">请输入邮箱！</p>').show();
		} else {
			// var formdata=commentform.serialize() + "&comment=" + noteContent ;
			// 添加状态信息
			statusdiv.html('<p>Processing...</p>').show();
			// 获取表单提交地址
			var formurl=commentform.attr('action');
			
			// 异步提交
			$.ajax({
					type: 'post',
					url: formurl,
					dataType:'json',
					data: {"comment_parent":comment_parent,"comment_post_ID":comment_post_ID, "_wp_unfiltered_html_comment":_wp_unfiltered_html_comment,"comment":comment,"url":url, "email":email,"author":author},
					error: function(XMLHttpRequest, textStatus, errorThrown){
					statusdiv.html('<p class="ajax-error" >数据不完整或表单提交太快了！</p>').show();
				},
				success: function(data, textStatus){
					if(data.errorno=="0") {
						$("#submit").prop('disabled', true);
						statusdiv.html('<p class="ajax-success" >笔记已提交审核，感谢分享笔记！</p>').show();
						alert('笔记已提交审核，感谢分享笔记！');
					}else{
						statusdiv.html('<p class="ajax-error" >'+data.msg+'</p>').show();
					}
					commentform.find('textarea[name=comment]').val('');
				}
			});
			setTimeout(function(){
		        $("#submit").prop('disabled', false);
		    }, 10*1000);
		}
		return false;

	});
	$(".comt-author").click(function() {
		href = $(this).children("a").attr("href");
		if(href.indexOf("/note/")!=-1) {
			var win = window.open(href, '_blank');
  			win.focus();
		}
	});
	$(".comt-meta span").hover(function(){
		$(this).children(".tooltip").css({ "opacity": 1, "pointer-events": "auto"});
	},function(){
		$(this).children(".tooltip").removeAttr("style");
	});
	/*
	$(".wrapper i").hover(function(){
		$(this).siblings(".tooltip").css({ "opacity": 1, "pointer-events": "auto"});
	},function(){
		$(this).siblings(".tooltip").css({ "opacity": 0, "pointer-events": "auto"});
	});
	*/
	//Upvote.create('runoobvote-id', {callback: vote_callback});
	var ajaxurl = 'https://www.runoob.com/wp-admin/admin-ajax.php';
	var callback = function(data) {
		//console.log($('#runoobvote-id').upvote('upvoted'));
		//console.log($('#runoobvote-id').upvote('downvoted'));
		//console.log(data);
		_vote_action = data.action;
		id_arr = data.id.split('-');
		um_id= id_arr[2];
		//console.log(um_id);
		
		var re = /^[1-9]+/;
		if (re.test(um_id)) { 
			var ajax_data = {
				_vote_action: _vote_action,
				action: "pinglun_zan",
				um_id: um_id,
				um_action: "ding"
			};
			//console.log(ajax_data);
			$.post(ajaxurl,ajax_data,function(status){
				//if(status.vote_num>999) {
				//	_voteHtml = '<span style="display: block; text-align: center;font-size: 20px; color: #6a737c; margin: 8px 0;">'+kFormatter(status.vote_num) +'</span>';
				//	$("#runoobvote-id-" + um_id + " .count").hide().after(_voteHtml);
				//}
				
			});
		}
	};
	if($('#comments').length && $('.upvotejs').length){
		$('.upvotejs').upvote({id: 660, callback: callback});
	
		$.post(ajaxurl,{"action":"pinglun_zan","postid":660},function(data){  
			$(data).each(function(key,value) {
				$("#runoobvote-id-" + value.commid + " .upvote").addClass(value.upvotejs_class);
				$("#runoobvote-id-" + value.commid + " .downvote").addClass(value.downvote_class);
				$("#runoobvote-id-" + value.commid + " .count").text(value.upvote_count);
			})
		},'json');
		
	}
	
	
});
function isBlank(str) {
    return (!str || /^\s*$/.test(str));
}
function kFormatter(num) {
	// return num;
    return Math.abs(num) > 999 ? Math.sign(num)*((Math.abs(num)/1000).toFixed(1)) + 'k' : Math.sign(num)*Math.abs(num)
}

</script>

<link rel="stylesheet" href="../0/qa.css?1.44">
<link rel="stylesheet" type="text/css" href="../0/simditor.min.css" />
<script type="text/javascript" src=""></script>
<script type="text/javascript" src=""></script>
<script type="text/javascript" src=""></script>
<script type="text/javascript" src=""></script>
<script type="text/javascript" src=""></script>
		<div class="sidebar-box ">
				

<style>	
.responsive_ad1 { display:none; }
@media(min-width: 800px) { .responsive_ad1 {  display:block;margin:0 auto;} }
</style>
<div id="ad-336280" >

<script async src=""
     crossorigin="anonymous"></script>
<!-- 移动版 自动调整 -->
<ins class="adsbygoogle"
     style="display:block"
     data-ad-client="ca-pub-5751451760833794"
     data-ad-slot="1691338467"
     data-ad-format="auto"
     data-full-width-responsive="true"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>
		</div>
				</div>
		
	</div>
</div>
	

<!-- 右边栏 -->
<div class="fivecol last right-column">

<style>
.sidebar-tree .double-li {
    width:300px;
}
.sidebar-tree .double-li li {
    width: 44%;
    line-height: 1.5em;
    border-bottom: 1px solid #ccc;
    float: left;
    display: inline;
}
</style>

    
        <div class="sidebar-box re-box re-box-large">
        <div class="sidebar-box recommend-here" style="margin: 0 auto;">
            <a href="javascript:void(0);" style="font-size: 16px; color:#64854c;font-weight:bold;"> <i class="fa fa-list" aria-hidden="true"></i> 分类导航</a>
        </div>
    <div class="sidebar-box sidebar-cate">
        
        <div class="sidebar-tree" >
            <ul><li style="margin: 0;"><a href="javascript:void(0);" class="tit"> HTML / CSS</a><ul class="double-li"><li><a title="HTML 教程" href="../html/html-tutorial.html">HTML 教程</a></li><li><a title="HTML5 教程" href="../html/html5-intro.html">HTML5 教程</a></li><li><a title="CSS 教程" href="../css/css-tutorial.html">CSS 教程</a></li><li><a title="CSS3 教程" href="../css3/css3-tutorial.html">CSS3 教程</a></li><li><a title="Bootstrap3 教程" href="../bootstrap/bootstrap-tutorial.html">Bootstrap3 教程</a></li><li><a title="Bootstrap4 教程" href="../bootstrap4/bootstrap4-tutorial.html">Bootstrap4 教程</a></li><li><a title="Bootstrap5 教程" href="../bootstrap5/bootstrap5-tutorial.html">Bootstrap5 教程</a></li><li><a title="Font Awesome 教程" href="../font-awesome/fontawesome-tutorial.html">Font Awesome 教程</a></li><li><a title="Foundation 教程" href="../foundation/foundation-tutorial.html">Foundation 教程</a></li></ul></li><li style="margin: 0;"><a href="javascript:void(0);" class="tit"> JavaScript</a><ul class="double-li"><li><a title="JavaScript 教程" href="../js/js-tutorial.html">JavaScript 教程</a></li><li><a title="HTML DOM 教程" href="../htmldom/htmldom-tutorial.html">HTML DOM 教程</a></li><li><a title="jQuery 教程" href="../jquery/jquery-tutorial.html">jQuery 教程</a></li><li><a title="AngularJS 教程" href="../angularjs/angularjs-tutorial.html">AngularJS 教程</a></li><li><a title="AngularJS2 教程" href="../angularjs2/angularjs2-tutorial.html">AngularJS2 教程</a></li><li><a title="Vue.js 教程" href="../vue2/vue-tutorial.html">Vue.js 教程</a></li><li><a title="Vue3 教程" href="../vue3/vue3-tutorial.html">Vue3 教程</a></li><li><a title="React 教程" href="../react/react-tutorial.html">React 教程</a></li><li><a title="TypeScript 教程" href="../typescript/ts-tutorial.html">TypeScript 教程</a></li><li><a title="jQuery UI 教程" href="../jqueryui/jqueryui-tutorial.html">jQuery UI 教程</a></li><li><a title="jQuery EasyUI 教程" href="../jeasyui/jqueryeasyui-tutorial.html">jQuery EasyUI 教程</a></li><li><a title="Node.js 教程" href="../nodejs/nodejs-tutorial.html">Node.js 教程</a></li><li><a title="AJAX 教程" href="../ajax/ajax-tutorial.html">AJAX 教程</a></li><li><a title="JSON 教程" href="../json/json-tutorial.html">JSON 教程</a></li><li><a title="Echarts 教程" href="../echarts/echarts-tutorial.html">Echarts 教程</a></li><li><a title="Chart.js 教程" href="../chartjs/chartjs-tutorial.html">Chart.js 教程</a></li><li><a title="Highcharts 教程" href="../highcharts/highcharts-tutorial.html">Highcharts 教程</a></li><li><a title="Google 地图 教程" href="../googleapi/google-maps-basic.html">Google 地图 教程</a></li></ul></li><li style="margin: 0;"><a href="javascript:void(0);" class="tit"> 服务端</a><ul class="double-li"><li><a title="Python 教程" href="../python3/python3-tutorial.html">Python 教程</a></li><li><a title="Python2.x 教程" href="../python/python-tutorial.html">Python2.x 教程</a></li><li><a title="Linux 教程" href="../linux/linux-tutorial.html">Linux 教程</a></li><li><a title="Docker 教程" href="../docker/docker-tutorial.html">Docker 教程</a></li><li><a title="Ruby 教程" href="../ruby/ruby-tutorial.html">Ruby 教程</a></li><li><a title="Java 教程" href="../java/java-tutorial.html">Java 教程</a></li><li><a title="C 教程" href="../c/c-tutorial.html">C 教程</a></li><li><a title="C++ 教程" href="../cplusplus/cpp-tutorial.html">C++ 教程</a></li><li><a title="Perl 教程" href="../perl/perl-tutorial.html">Perl 教程</a></li><li><a title="Servlet 教程" href="../servlet/servlet-tutorial.html">Servlet 教程</a></li><li><a title="JSP 教程" href="../jsp/jsp-tutorial.html">JSP 教程</a></li><li><a title="Lua 教程" href="../lua/lua-tutorial.html">Lua 教程</a></li><li><a title="Rust 教程" href="../rust/rust-tutorial.html">Rust 教程</a></li><li><a title="Scala 教程" href="../scala/scala-tutorial.html">Scala 教程</a></li><li><a title="Go 教程" href="../go/go-tutorial.html">Go 教程</a></li><li><a title="PHP 教程" href="../php/php-tutorial.html">PHP 教程</a></li><li><a title="数据结构与算法" href="../data-structures/data-structures-tutorial.html">数据结构与算法</a></li><li><a title="Django 教程" href="../django/django-tutorial.html">Django 教程</a></li><li><a title="Zookeeper 教程" href="../w3cnote/zookeeper-tutorial.html">Zookeeper 教程</a></li><li><a title="设计模式" href="../design-pattern/design-pattern-tutorial.html">设计模式</a></li><li><a title="正则表达式" href="../regexp/regexp-tutorial.html">正则表达式</a></li><li><a title="Maven 教程" href="../maven/maven-tutorial.html">Maven 教程</a></li><li><a title="Verilog 教程" href="../w3cnote/verilog-tutorial.html">Verilog 教程</a></li><li><a title="ASP 教程" href="../asp/asp-tutorial.html">ASP 教程</a></li><li><a title="AppML 教程" href="../appml/appml-tutorial.html">AppML 教程</a></li><li><a title="VBScript 教程" href="../vbscript/vbscript-tutorial.html">VBScript 教程</a></li></ul></li><li style="margin: 0;"><a href="javascript:void(0);" class="tit"> 数据库</a><ul class="double-li"><li><a title="SQL 教程" href="../sql/sql-tutorial.html">SQL 教程</a></li><li><a title="MySQL 教程" href="../mysql/mysql-tutorial.html">MySQL 教程</a></li><li><a title="PostgreSQL 教程" href="../postgresql/postgresql-tutorial.html">PostgreSQL 教程</a></li><li><a title="SQLite 教程" href="../sqlite/sqlite-tutorial.html">SQLite 教程</a></li><li><a title="MongoDB 教程" href="../mongodb/mongodb-tutorial.html">MongoDB 教程</a></li><li><a title="Redis 教程" href="../redis/redis-tutorial.html">Redis 教程</a></li><li><a title="Memcached 教程" href="../Memcached/Memcached-tutorial.html">Memcached 教程</a></li></ul></li><li style="margin: 0;"><a href="javascript:void(0);" class="tit"> 数据分析</a><ul class="double-li"><li><a title="Python 教程" href="../python3/python3-tutorial.html">Python 教程</a></li><li><a title="NumPy 教程" href="../numpy/numpy-tutorial.html">NumPy 教程</a></li><li><a title="Pandas 教程" href="../pandas/pandas-tutorial.html">Pandas 教程</a></li><li><a title="Matplotlib 教程" href="../matplotlib/matplotlib-tutorial.html">Matplotlib 教程</a></li><li><a title="Scipy 教程" href="../scipy/scipy-tutorial.html">Scipy 教程</a></li><li><a title="R 教程" href="../r/r-tutorial.html">R 教程</a></li><li><a title="Julia 教程" href="../julia/julia-tutorial.html">Julia 教程</a></li></ul></li><li style="margin: 0;"><a href="javascript:void(0);" class="tit"> 移动端</a><ul class="double-li"><li><a title="Android 教程" href="../w3cnote/android-tutorial-intro.html">Android 教程</a></li><li><a title="Swift 教程" href="../swift/swift-tutorial.html">Swift 教程</a></li><li><a title="jQuery Mobile 教程" href="../jquerymobile/jquerymobile-tutorial.html">jQuery Mobile 教程</a></li><li><a title="ionic 教程" href="../ionic/ionic-tutorial.html">ionic 教程</a></li><li><a title="Kotlin 教程" href="../kotlin/kotlin-tutorial.html">Kotlin 教程</a></li></ul></li><li style="margin: 0;"><a href="javascript:void(0);" class="tit"> XML 教程</a><ul class="double-li"><li><a title="XML 教程" href="../xml/xml-tutorial.html">XML 教程</a></li><li><a title="DTD 教程" href="../dtd/dtd-tutorial.html">DTD 教程</a></li><li><a title="XML DOM 教程" href="../dom/dom-tutorial.html">XML DOM 教程</a></li><li><a title="XSLT 教程" href="../xsl/xsl-tutorial.html">XSLT 教程</a></li><li><a title="XPath 教程" href="../xpath/xpath-tutorial.html">XPath 教程</a></li><li><a title="XQuery 教程" href="../xquery/xquery-tutorial.html">XQuery 教程</a></li><li><a title="XLink 教程" href="../xlink/xlink-tutorial.html">XLink 教程</a></li><li><a title="XPointer 教程" href="../xlink/xlink-tutorial.html">XPointer 教程</a></li><li><a title="XML Schema 教程" href="../schema/schema-tutorial.html">XML Schema 教程</a></li><li><a title="XSL-FO 教程" href="../xslfo/xslfo-tutorial.html">XSL-FO 教程</a></li><li><a title="SVG 教程" href="../svg/svg-tutorial.html">SVG 教程</a></li></ul></li><li style="margin: 0;"><a href="javascript:void(0);" class="tit"> ASP.NET</a><ul class="double-li"><li><a title="ASP.NET 教程" href="../aspnet/aspnet-tutorial.html">ASP.NET 教程</a></li><li><a title="C# 教程" href="../csharp/csharp-tutorial.html">C# 教程</a></li><li><a title="Web Pages 教程" href="../aspnet/webpages-intro.html">Web Pages 教程</a></li><li><a title="Razor 教程" href="../aspnet/razor-intro.html">Razor 教程</a></li><li><a title="MVC 教程" href="../aspnet/mvc-intro.html">MVC 教程</a></li><li><a title="Web Forms 教程" href="../aspnet/aspnet-intro.html">Web Forms 教程</a></li></ul></li><li style="margin: 0;"><a href="javascript:void(0);" class="tit"> Web Service</a><ul class="double-li"><li><a title="Web Service 教程" href="../webservices/webservices-tutorial.html">Web Service 教程</a></li><li><a title="WSDL 教程" href="../wsdl/wsdl-tutorial.html">WSDL 教程</a></li><li><a title="SOAP 教程" href="../soap/soap-tutorial.html">SOAP 教程</a></li><li><a title="RSS 教程" href="../rss/rss-tutorial.html">RSS 教程</a></li><li><a title="RDF 教程" href="../rdf/rdf-tutorial.html">RDF 教程</a></li></ul></li><li style="margin: 0;"><a href="javascript:void(0);" class="tit"> 开发工具</a><ul class="double-li"><li><a title="Eclipse 教程" href="../eclipse/eclipse-tutorial.html">Eclipse 教程</a></li><li><a title="Git 教程" href="../git/git-tutorial.html">Git 教程</a></li><li><a title="Svn 教程" href="../svn/svn-tutorial.html">Svn 教程</a></li><li><a title="Markdown 教程" href="../markdown/md-tutorial.html">Markdown 教程</a></li></ul></li><li style="margin: 0;"><a href="javascript:void(0);" class="tit"> 网站建设</a><ul class="double-li"><li><a title="HTTP 教程" href="../http/http-tutorial.html">HTTP 教程</a></li><li><a title="网站建设指南" href="../web/web-buildingprimer.html">网站建设指南</a></li><li><a title="浏览器信息" href="../browsers/browser-information.html">浏览器信息</a></li><li><a title="网站主机教程" href="../hosting/hosting-tutorial.html">网站主机教程</a></li><li><a title="TCP/IP 教程" href="../tcpip/tcpip-tutorial.html">TCP/IP 教程</a></li><li><a title="W3C 教程" href="../w3c/w3c-tutorial.html">W3C 教程</a></li><li><a title="网站品质" href="../quality/quality-tutorial.html">网站品质</a></li></ul></li></ul>            </div>
    
    </div>
    </div>
    <br>
    
    <div class="sidebar-box re-box re-box-large">
        <div class="sidebar-box recommend-here">
            <a href="javascript:void(0);">Advertisement</a>
        </div>
        <div class="re-600160" id="sidebar-right-re">
                <script async src=""></script>
        <!-- 侧栏1 -->
        <ins class="adsbygoogle"
             style="display:inline-block;width:160px;height:600px"
             data-ad-client="ca-pub-5751451760833794"
             data-ad-slot="4106274865"></ins>
        <script>
        (adsbygoogle = window.adsbygoogle || []).push({});
        </script>
                </div>
    </div>
</div></div>

</div>

<script>
var aid = 660;
function coll() {
	$.post( '/wp-content/themes/runoob/option/user/userinfo.php', {aid:aid, action:"collarticle", opt:'add'},function( data ) {
		if(data.error==0) {
			$("#content").find("h1:first").find("a").attr("href","javascript:void(0);");
			$("#content").find("h1:first").find("img").attr("src","http://www.runoob.com/wp-content/themes/runoob/assets/img/coll2.png").css({width:32+"px",height:32+"px"});
		}
		alert(data.msg);
	},'json');
}
</script>


<!-- 反馈对话框开始 -->
<script src=""></script>
<link rel="stylesheet" href="../0/feedback.css?1.0" />
<script type="text/javascript">
$.feedback({
    ajaxURL: '/feedback/runoob_feedback.php',
	html2canvasURL: '/wp-content/themes/runoob/assets/feedback/stable/2.0/html2canvas.js',
	onClose: function () {
         window.location.reload();
    }
});
</script>
<!-- 反馈对话框结束 -->
<button class="feedback-btn feedback-btn-gray">反馈/建议</button>
<!-- 底部 -->
<div id="footer" class="mar-t50">
   <div class="runoob-block">
    <div class="runoob cf">
     <dl>
      <dt>
       在线实例
      </dt>
      <dd>
       &middot;<a target="_blank" href="../html/html-examples.html">HTML 实例</a>
      </dd>
      <dd>
       &middot;<a target="_blank" href="../css/css-examples.html">CSS 实例</a>
      </dd>
      <dd>
       &middot;<a target="_blank" href="../js/js-examples.html">JavaScript 实例</a>
      </dd>
      <dd>
       &middot;<a target="_blank" href="../ajx/ajax-examples.html">Ajax 实例</a>
      </dd>
       <dd>
       &middot;<a target="_blank" href="../jquery/jquery-examples.html">jQuery 实例</a>
      </dd>
      <dd>
       &middot;<a target="_blank" href="../xml/xml-examples.html">XML 实例</a>
      </dd>
      <dd>
       &middot;<a target="_blank" href="../java/java-examples.html">Java 实例</a>
      </dd>
     
     </dl>
     <dl>
      <dt>
      字符集&工具
      </dt>
      <dd>
       &middot; <a target="_blank" href="../charsets/html-charsets.html">HTML 字符集设置</a>
      </dd>
      <dd>
       &middot; <a target="_blank" href="../tags/html-ascii.html">HTML ASCII 字符集</a>
      </dd>
     <dd>
       &middot; <a target="_blank" href="https://c.runoob.com/front-end/6939/">JS 混淆/加密</a>
      </dd> 
      <dd>
       &middot; <a target="_blank" href="https://c.runoob.com/front-end/6232/">PNG/JPEG 图片压缩</a>
      </dd>
      <dd>
       &middot; <a target="_blank" href="../tags/html-colorpicker.html">HTML 拾色器</a>
      </dd>
      <dd>
       &middot; <a target="_blank" href="..//c.runoob.com/front-end/53">JSON 格式化工具</a>
      </dd>
      <dd>
       &middot; <a target="_blank" href="..//c.runoob.com/front-end/6680/">随机数生成器</a>
      </dd>
     </dl>
     <dl>
      <dt>
       最新更新
      </dt>
                   <dd>
       &middot;
      <a href="../matplotlib/matplotlib-imread.html" title="Matplotlib imread() 方法">Matplotlib imre...</a>
      </dd>
              <dd>
       &middot;
      <a href="../matplotlib/matplotlib-imsave.html" title="Matplotlib imsave() 方法">Matplotlib imsa...</a>
      </dd>
              <dd>
       &middot;
      <a href="../matplotlib/matplotlib-imshow.html" title="Matplotlib imshow() 方法">Matplotlib imsh...</a>
      </dd>
              <dd>
       &middot;
      <a href="../matplotlib/matplotlib-hist.html" title="Matplotlib 直方图">Matplotlib 直方图</a>
      </dd>
              <dd>
       &middot;
      <a href="../python3/python-func-object.html" title="Python object() 函数">Python object()...</a>
      </dd>
              <dd>
       &middot;
      <a href="../python3/python-ai-draw.html" title="Python AI 绘画">Python AI 绘画</a>
      </dd>
              <dd>
       &middot;
      <a href="../w3cnote/cursor-editor.html" title="神辅助 Cursor 编辑器，加入 GPT-4 让编码更轻松！">神辅助 Cursor ...</a>
      </dd>
             </dl>
     <dl>
      <dt>
       站点信息
      </dt>
      <dd>
       &middot;
       <a target="_blank" href="mailto:admin@runoob.com" rel="external nofollow">意见反馈</a>
       </dd>
      <dd>
       &middot;
      <a target="_blank" href="../disclaimer">免责声明</a>
       </dd>
      <dd>
       &middot;
       <a target="_blank" href="../aboutus">关于我们</a>
       </dd>
      <dd>
       &middot;
      <a target="_blank" href="../archives">文章归档</a>
      </dd>
    
     </dl>
    
     <div class="search-share">
      <div class="app-download">
        <div>
         <strong>关注微信</strong>
        </div>
      </div>
      <div class="share">
      <img width="128" height="128" src="/wp-content/themes/runoob/assets/images/qrcode.png" />
       </div>
     </div>
     
    </div>
   </div>
   <div class="w-1000 copyright">
     Copyright &copy; 2013-2023    <strong><a href="../" target="_blank">菜鸟教程</a></strong>&nbsp;
    <strong><a href="../" target="_blank">runoob.com</a></strong> All Rights Reserved. 备案号：<a target="_blank" rel="nofollow" href="https://beian.miit.gov.cn/">闽ICP备15012807号-1</a>
   </div>
  </div>
  <div class="fixed-btn">
    <a class="go-top" href="javascript:void(0)" title="返回顶部"> <i class="fa fa-angle-up"></i></a>
    <a class="qrcode"  href="javascript:void(0)" title="关注我们"><i class="fa fa-qrcode"></i></a>
    <a class="writer" style="display:none" href="javascript:void(0)"   title="标记/收藏"><i class="fa fa-star" aria-hidden="true"></i></a>
    <!-- qrcode modal -->
    <div id="bottom-qrcode" class="modal panel-modal hide fade in">
      <h4>微信关注</h4>
      <div class="panel-body"><img alt="微信关注" width="128" height="128" src="/wp-content/themes/runoob/assets/images/qrcode.png"></div> 
    </div>
  </div>

 <div style="display:none;">
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-84264393-2"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());

  gtag('config', 'UA-84264393-2');
</script>
<script>
var _hmt = _hmt || [];
(function() {
  var hm = document.createElement("script");
  hm.src = "https://hm.baidu.com/hm.js?3eec0b7da6548cf07db3bc477ea905ee";
  var s = document.getElementsByTagName("script")[0]; 
  s.parentNode.insertBefore(hm, s);
})();
</script>

</div>
<script>
window.jsui={
    www: 'https://www.runoob.com',
    uri: 'https://www.runoob.com/wp-content/themes/runoob'
};
</script>

<script src=""></script>
<script src=""></script>

</body>
</html>